Solved

Change IP addresses and netmask and gateway on multiple VM's

Posted on 2014-02-26
13
1,905 Views
Last Modified: 2014-03-10
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.
0
Comment
Question by:Kay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 13

Assisted Solution

by:Abhilash
Abhilash earned 250 total points
ID: 39888427
You can use the Set-VMGuestNetworkInterface cmdlet to do it.
Check this link the example syntax.
https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Set-VMGuestNetworkInterface.html
0
 
LVL 122
ID: 39888450
use this script with PowerCLI

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> 

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.
0
 
LVL 13

Expert Comment

by:Abhilash
ID: 39888465
@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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 122
ID: 39888507
@Abhilash Hb - is it ? did you check all the script?

and then PIPED through a Set-VMGuestNetworkInterface

a working example of code,  see all the code.

Set-VMGuestNetworkInterface

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> 

Open in new window

0
 

Author Comment

by:Kay
ID: 39888644
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?
0
 
LVL 13

Expert Comment

by:Abhilash
ID: 39888674
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.
0
 
LVL 122
ID: 39888686
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?
0
 

Author Comment

by:Kay
ID: 39889079
yes that's correct, virtual machine port group
0
 
LVL 122

Accepted Solution

by:
Andrew Hancock (VMware vExpert / EE MVE^2) earned 250 total points
ID: 39889619
get-vm | get-networkadapter | where-object { $_.networkname -like "CurrentVirtualMachinePortGroup" } | set-networkadapter -networkname "NewVirtualMachinePortGroup" -Confirm:$false

Open in new window

0
 

Author Comment

by:Kay
ID: 39900097
the code:

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>

Doesn't work, I get this error message below:



Get-VMGuestNetworkInterface : 03/03/2014 11:01:50    Get-VMGuestNetworkInterface        Unable to access file
<unspecified filename>
At line:1 char:25
+ Get-VM DEV-QRE-DEL-10 | Get-VMGuestNetworkInterface -GuestUser uat\kabiru -Guest ...
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-VMGuestNetworkInterface], CannotAccessFile
    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets
   .Commands.GetVmGuestNetworkInterface
0
 

Author Comment

by:Kay
ID: 39900115
I am going to use this script instead:

$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")

Open in new window


What does the , 1 mean on the $wmi.SetGateways("10.0.0.1", 1)?
0
 

Author Comment

by:Kay
ID: 39900118
this doesn't work either because of the IP addresses!
0
 

Author Comment

by:Kay
ID: 39900818
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

0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Teach the user how to use create log bundles for vCenter Server or ESXi hosts Open vSphere Web Client: Generate vCenter Server and ESXi host log bundle:  Open vCenter Server Appliance Web Management interface and generate log bundle: Open vCenter Se…
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question