Kelly Garcia
asked on
Change IP addresses and netmask and gateway on multiple VM's
Hi Guys,
I have a list of virtual machine's IP addresses they are all VMware managed by a vcenter server.
I need to change the ip addresses, Netmask, Gateway, and the port group for every single one.
What is the quickest way of doing this, is there a powercli command I can use?
Thank you all for the support.
I have a list of virtual machine's IP addresses they are all VMware managed by a vcenter server.
I need to change the ip addresses, Netmask, Gateway, and the port group for every single one.
What is the quickest way of doing this, is there a powercli command I can use?
Thank you all for the support.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Andrew
The command you gave is to retrieve the information.
Its a GET command. The author of the question is asking how to set these parameters.
The command you gave is to retrieve the information.
Its a GET command. The author of the question is asking how to set these parameters.
@Abhilash Hb - is it ? did you check all the script?
and then PIPED through a Set-VMGuestNetworkInterfac e
a working example of code, see all the code.
Set-VMGuestNetworkInterfac e
and then PIPED through a Set-VMGuestNetworkInterfac
a working example of code, see all the code.
Set-VMGuestNetworkInterfac
Get-VM VMName | Get-VMGuestNetworkInterface -GuestUser Administrator -GuestPassword <password> -HostUser root -HostPassword <password> | Set-VMGuestNetworkInterface -IPPolicy Static -Ip <IPAddress> -Netmask 255.255.252.0 -Gateway <Gateway> -GuestUser Administrator -GuestPassword <password> -HostUser root -HostPassword <password>
ASKER
I am going to connect, using vi-connect, to a vcenter server, so I presume I wont need the -HostUser root -HostPassword <password>
Also do we need the -GuestUser -GuestPassword <password> twice in the pipelines?
I also need to change the port group, how do I add this to the script?
Also do we need the -GuestUser -GuestPassword <password> twice in the pipelines?
I also need to change the port group, how do I add this to the script?
Yes. You can create a input value and input it when it pops up but in this above case yes you will have to do it twice.
Once for Get and once for Set.
Once for Get and once for Set.
If you are connected to vCenter Server, no host options needed.
username and password requried twice for two functions, the first is get the network adaptor, and the second is set the IP address.
virtual machine portgroup I assume?
username and password requried twice for two functions, the first is get the network adaptor, and the second is set the IP address.
virtual machine portgroup I assume?
ASKER
yes that's correct, virtual machine port group
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the code:
Get-VM VMName | Get-VMGuestNetworkInterfac e -GuestUser Administrator -GuestPassword <password> -HostUser root -HostPassword <password> | Set-VMGuestNetworkInterfac e -IPPolicy Static -Ip <IPAddress> -Netmask 255.255.252.0 -Gateway <Gateway> -GuestUser Administrator -GuestPassword <password> -HostUser root -HostPassword <password>
Doesn't work, I get this error message below:
Get-VMGuestNetworkInterfac e : 03/03/2014 11:01:50 Get-VMGuestNetworkInterfac e Unable to access file
<unspecified filename>
At line:1 char:25
+ Get-VM DEV-QRE-DEL-10 | Get-VMGuestNetworkInterfac e -GuestUser uat\kabiru -Guest ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VMGuestNetworkInterfa ce], CannotAccessFile
+ FullyQualifiedErrorId : Client20_VmGuestServiceImp l_RunScrip tInGuest_V iError,VMw are.VimAut omation.Vi Core.Cmdle ts
.Commands.GetVmGuestNetwor kInterface
Get-VM VMName | Get-VMGuestNetworkInterfac
Doesn't work, I get this error message below:
Get-VMGuestNetworkInterfac
<unspecified filename>
At line:1 char:25
+ Get-VM DEV-QRE-DEL-10 | Get-VMGuestNetworkInterfac
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VMGuestNetworkInterfa
+ FullyQualifiedErrorId : Client20_VmGuestServiceImp
.Commands.GetVmGuestNetwor
ASKER
I am going to use this script instead:
What does the , 1 mean on the $wmi.SetGateways("10.0.0.1 ", 1)?
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$wmi.EnableStatic("10.0.0.15", "255.255.255.0")
$wmi.SetGateways("10.0.0.1", 1)
$wmi.SetDNSServerSearchOrder("10.0.0.100")
What does the , 1 mean on the $wmi.SetGateways("10.0.0.1
ASKER
this doesn't work either because of the IP addresses!
ASKER
for the port group that's the way I've done my script, I didn't want to do the foreeach, however I am having to press enter each time, is there a way around it - not pressing enter to process the next command?
Get-VM DEV-QRE-pro-12 | get-networkadapter | set-networkadapter -networkname "VM_Build_2262" -Confirm:$false
Get-VM DEV-QRE-pro-13 | get-networkadapter | set-networkadapter -networkname "VM_Build_2262" -Confirm:$false
Get-VM DEV-QRE-pro-14 | get-networkadapter | set-networkadapter -networkname "VM_Build_2262" -Confirm:$false
Get-VM DEV-QRE-pro-15 | get-networkadapter | set-networkadapter -networkname "VM_Build_2262" -Confirm:$false
Get-VM DEV-QRE-pro-16 | get-networkadapter | set-networkadapter -networkname "VM_Build_2262" -Confirm:$false
Get-VM DEV-QRE-pro-17 | get-networkadapter | set-networkadapter -networkname "VM_Build_2262" -Confirm:$false
Open in new window
Make sure VMware Tools is installed in the VM.
VMName is the name of the VM in the inventory.
GuestUser and GuestPassword our Guest Userids and Passwords, so if AD, they are AD usernames and passwords to enable login to the VM.
I think IP Address and Gateway address are self-explanatory.
HostUser and Hostpassword are Host usernames and passwords.