Change the IP address of a Windows servers with VMware PowerClI script

VMware vSphere PowerCLI script to change the IP addresses of Windows servers.

$TranscriptFile = “.\change-ip-2.txt”
#Stop-Transcript
Start-Transcript -Path $TranscriptFile

$windowsID = “administrator”
$windowsPassword = “MyPassword”

Function Set-WinVMIP ($VM, $IP, $SNM, $gateway){

$nics = Get-VMGuestNetworkInterface -VM $VM -GuestUser $windowsID -GuestPassword $windowsPassword | ?{$_.ip -ne $null}

Write-Host “Changing IP for $VM to $IP” -BackgroundColor DarkBlue

Set-VMGuestNetworkInterface -vmguestnetworkinterface $nics -Ip $IP -Netmask $SNM -Gateway $gateway -Dns $dns1,$dns2 -GuestUser $windowsID -GuestPassword $windowsPassword

write-host “+++++++++++++++++++++++”
}

#Connect-VIServer localhost

$data = “./IP-LIST2.csv”
$list = import-csv $data

foreach ($line in $list)
{

$VM = $line.VM
$IP = $line.IP
$SNM = “255.255.255.0”
$gateway = “192.168.0.1”
$nic = $line.Name
$dns1 = “192.168.0.11”
$dns2 = “192.168.0.12”

Set-WinVMIP $VM $IP $SNM $gateway

}

Get-Date
Stop-Transcript
Invoke-Item $TranscriptFile

About Andrew Lin

Hi, I have always wanted to creat a blog site but never had the time. I have been working in Information Technology for over 15 years. I specialize mainly in networks and server technologies and dabble a little with the programming aspects. Andrew Lin

View all posts by Andrew Lin →