Hi,
I am looking how can change IP address on 25 VM . on VMs are is windows os and all had install vmware tool.
Then you should be able to do something like this.
You might have to add credentials for the guest on the Invoke-VMScript cmdlet.
`$if = Get-NetAdapter -Physical | where{`$_.LinkLayerAddress -eq '$mac'}
New-NetIPAddress -InterfaceIndex `$if.ifIndex -IPAddress $ip -PrefixLength $prefix
'@
$vmName = 'MyVM'
$ip = '192.168.1.111'
$prefix = '24'
$vm = Get-VM -Name $vmName
$nic = Get-NetworkAdapter -VM $vm -Name 'Network adapter 1'
$mac = $nic.MacAddress.Replace(':', '-')
Invoke-VMScript -VM $vm -ScriptType Powershell -ScriptText $ExecutionContext.InvokeCommand.ExpandString($code)
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Which Windows version do these VMs have?
Is PowerShell enabled in the guest OS?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
HI , LucD
Its windows 2016 and there are in workgroup no domain .
Powershell is enabled.
Then you should be able to do something like this.
You might have to add credentials for the guest on the Invoke-VMScript cmdlet.
`$if = Get-NetAdapter -Physical | where{`$_.LinkLayerAddress -eq '$mac'}
New-NetIPAddress -InterfaceIndex `$if.ifIndex -IPAddress $ip -PrefixLength $prefix
'@
$vmName = 'MyVM'
$ip = '192.168.1.111'
$prefix = '24'
$vm = Get-VM -Name $vmName
$nic = Get-NetworkAdapter -VM $vm -Name 'Network adapter 1'
$mac = $nic.MacAddress.Replace(':', '-')
Invoke-VMScript -VM $vm -ScriptType Powershell -ScriptText $ExecutionContext.InvokeCommand.ExpandString($code)
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is this script for changing for MAC or IP?
To me, its look its for MAC
No, it uses the MAC address to find the correct NIC inside the guest OS.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd , I try script and it add a new ip address like a second one. Old IP address is still ramain.
That is correct, the New-NetIPAddress creates a new IP address and makes the existing IP address a secondary address.
If you want to remove the old IP address, you will have to use Remove-NetIPAddress first, before doing the New-NetIPAddress.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference