Benötigen Sie Hilfe beim Erstellen eines einzelnen Powershell-Skripts, das mit Windows 7 (Powershell 2.0) und Windows 10 (Powershell 5.0) funktioniert, sodass ich es pushen kann über GPO. * Wir haben keine Domäne DHCP war wir bekommen IP von MPLS-Router mietet ...Powershell-Skript zum Festlegen neuer DNS-Einstellungen in Windows 7 und Windows 10 mit einem Skript
Bisher habe ich für Fenster die folgenden mit einer Batch-Datei ausgeführt haben 7 (Nicht-Powershell)
@ECHO OFF
set vardns1=1.1.1.1
set vardns2=2.2.2.2
ECHO Setting Primary DNS
netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%
ECHO Setting Secondary DNS
netsh int ip add dns name = "Local Area Connection" addr = %vardns2%
ECHO Flushing DNS
ipconfig /flushdns
ECHO Registering New DNS settings
ipconfig /registerdns
Und das Code für Windows 10 (Power 5,0)
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent
()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
Exit
}
#The servers that we want to use
$newDNSServers = "1.1.1.1","2.2.2.2"
# Get all network adapters that already have DNS servers set
$adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DNSServerSearchOrder -ne $null}
# Set the DNS server search order for all of the previously-found adapters
$adapters | ForEach-Object {$_.SetDNSServerSearchOrder($newDNSServers)}
#Flushing DNS
ipconfig /flushdns
#Registering DNS
ipconfig /registerdns
Set-DnsClientGlobalSetting -SuffixSearchList @("mydomain.local")