Well, I’ve been playing around with PowerShell today. I had the task to move (as in change the IP address) two domain controllers into another VLAN. I could have done it the easy way and added the DNS servers by hand (by RDP’ing to each system having these particular DNS servers configured) - which wouldn’t have been very hard considering the domain only has 7 members at this point …

I wanted to do it the proper way, so I ended up asking old uncle Google, and it supplied me with the answers I was looking for.

1
2
3
4
5
6
7
PS > Get-ADComputer -SearchBase `
'OU=Server,OU=Devicesdc=ka,dc=home,dc=heimdaheim,dc=de' `
-Filter '*' | Select dnshostname | foreach {
>> Invoke-Command -ScriptBlock {Get-NetAdapter -Name Ethernet | `
Set-DnsClientServerAddress -ServerAddresses ("10.76.15.20", "10.76.15.20", "10.75.20.20", "10.75.20.21")} `
-ComputerName $_.dnshostname
>> }

Now, I executed those few PowerShell lines before changing the IP address of both domain controllers (10.76.15.20 being the old IP and 10.76.20.20 being the new one). After that I changed the IP address on the second (and after a short downtime) on the first domain controller. After both were restored and available again (and I checked with repadmin /showrepl), I ran the script again, this time only setting the new DCs:

1
2
3
4
5
6
7
PS > Get-ADComputer -SearchBase `
'OU=Server,OU=Devicesdc=ka,dc=home,dc=heimdaheim,dc=de' `
-Filter '*' | Select dnshostname | foreach {
>> Invoke-Command -ScriptBlock {Get-NetAdapter -Name Ethernet | `
Set-DnsClientServerAddress -ServerAddresses ("10.75.20.20", "10.75.20.21")} `
-ComputerName $_.dnshostname
>> }

Well, considering the time I spent on looking for this and the time I would have needed to change even the seven members - even this is a time saver.