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”
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 = “”
$gateway = “”
$nic = $line.Name
$dns1 = “”
$dns2 = “”

Set-WinVMIP $VM $IP $SNM $gateway


Invoke-Item $TranscriptFile

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *