I want to change the interfaces of all computers of two AD OUs. Currently all interfaces have static IPs and DNS servers. I wrote this Powershell Script:
$getIP = get-netipaddress | Where-Object IPAddress -Like "192.168.18.*"
$index = $getip.InterfaceIndex
Get-NetIPInterface | where-Object InterfaceIndex -like "$index" | Set-NetIPInterface -Dhcp Enabled
$rep = Get-NetIPInterface | where-Object InterfaceIndex -like "$index"
$rep1 = $rep.InterfaceAlias
$Hostn = hostname
$Test = Get-NetIPInterface -InterfaceIndex $index | Where-Object {$_.Dhcp -like "Enabled"}
if ($Test){
$DHCPSTATUS = "DHCP active"
$report = "The Interface $Rep1 on $Hostn was set to DHCP . The DNS Server are resettet"
Set-DnsClientServerAddress -InterfaceIndex "$index" -ResetServerAddresses
}
else{
$DHCPSTATUS = "DHCP_not_active"
$report = "The Interface $Rep1 on $Hostn was NOT set to DHCP . The DNS Server are NOT resettet"
}
$report | Out-File \\Server\d$\DHCP\Result\$Hostn"_"$DHCPSTATUS.txt
For the two OUs I enabled a GPO with a Startscript: https://i.stack.imgur.com/ZSZbV.png
When I run gpresult, It shows that the GPO was used, but nothing happened to the interface, neither was a txt written.