VMware Cloud Community
arindama
Contributor
Contributor

Re IP all windows VM in a VMware cluster, using vCenter login.

Hi Experts,

We have a requirement here to re IP all our VM's as we are moving to a new data center.

While trying to do so, I found a very good script from vmnomad.blogspot.com which I later customized to our need.

Script is running fine with the required parameters & updates, but its not able to change the IP address, though it says, it changed the IP address.

Command syntax from PowerCLI: NewreIP1.ps1 -Inventory .\Test-Inventory5.csv -VC vCenter

I think, this command syntax invoke-vmscript -ScriptText $changingIp -ScriptType bat -VM $vm.ServerName -GuestUser $vm.Username -GuestPassword $vm.Password  is not able to execute forcefully on the VM, the way it should.

Previous line output provides data perfectly, the ones which needs to be changed:

$changingIp = '%WINDIR%\system32\netsh.exe interface ipv4 set address name="' + $InterfaceName + '" source=static address=' + $vm.newIP + ' mask=' + $vm.newMask + ' gateway=' + $vm.newGateway + ' gwmetric=1 store=persistent'

Write-Host $changingIp

The script is added here as an attachment.

I tried to run the output of Write-Host $changingIp in couple of my VM's manually & they were able to change the IP address based on the data provided without any issues.

So, somehow Invoke-VMscript is not able to run on the VM with data acquired.

Any help will be great!

Thanks

Arindam

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership

Is UAC enabled in the guest OS?
You probably are getting a prompt in that case.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arindama
Contributor
Contributor

Hi LucD,

I'll check UAC status, but i do not get any prompt in any VM or in PowerCLI while running the script. I have 300 plus VM's to work on, so is there a automated process?

I noticed that Write-Host $changingIp prints the right data, but invoke-vmscript is not able to execute it on the VM.

Is there a force execution of invoke-vmscript? Tried to run as 'runas /user:Administrator cmd.exe %WINDIR%\system32\netsh.exe ... ' but did not change anything.

Everytime it prints the IP has been changed, but actually does not change anything, only the portgroup changes.

Am I missing something here?

Thanks
Arindam

Reply
0 Kudos
LucD
Leadership
Leadership

The easiest way to check is disable UAC and run the Invoke-VMScript again.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arindama
Contributor
Contributor

Hi LucD,

I tries & yes by disabling UAC(EnableLUA registry key value to 0) the script runs properly changing the IP address.

Thanks for the direction.

But we have a different problem now.

I need to make this change on 300 plus VM's & disabling UAC with another script is not an issue.

But problem is with restarting all 300 servers, which is an impossible option. And without restart Script is not able to make the change on remote server.

Is there a way we can update server without restart, so that the script can run properly?

I found some batch command, which might work:

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f 

net stop server && net start server 

But not sure how to frame it within a Powershell script.

Any idea how to disable UAC on all 300 servers, without a reboot?

 

Thanks

Arindam

Reply
0 Kudos
LucD
Leadership
Leadership

You might want to try with

New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Value 00000000 -PropertyType "DWord"

This should remove the UAC prompt, but I'm not 100% sure it will work in all cases.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arindama
Contributor
Contributor

Thanks LucD,

Let me try this.

But will this avoid a restart? Thats what I am most worried about. Let me check.

 

Thanks

Arindam

Reply
0 Kudos
arindama
Contributor
Contributor

Hi Lucd,

It works & I have set it in a seperate script.

But for Windows 2016 machines, its looking for a restart to make this registry change active.

Thats what i observed till now, testing more.

 

Thanks

Arindam

Reply
0 Kudos
LucD
Leadership
Leadership

According to the MSFT documentation about User Account Control Group Policy and registry key settings, this should work the same for Windows 10 and Windows 2016.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arindama
Contributor
Contributor

Getting vmware error now.
Reply
0 Kudos
LucD
Leadership
Leadership

Did you restart the target VM after all these trials?

This looks like the VMware Tools are in a funny state.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arindama
Contributor
Contributor

I know, thats what it looks like.

But all machines VMtools are current, 10305 as it says.

Only difference is, these VM's are in a seperate cluster.

 

Thanks

Arindam

Reply
0 Kudos
LucD
Leadership
Leadership

But did you restart the VM before using the script?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
arindama
Contributor
Contributor

No, I did not restart.
Reply
0 Kudos