The following script allows the user to modify an MS Windows Guest VM IP and DNS configuration. You may download the ‘IP&DNS_Modification.ps1‘ script HERE (Remove the .doc extension). Begin by […]
The following script allows the user to modify an MS Windows Guest VM IP and DNS configuration. You may download the ‘IP&DNS_Modification.ps1‘ script HERE (Remove the .doc extension).
Begin by entering the ESXi/Vcenter Host IP Address, username and password:
A list of all VM’s residing in ESXi/Vcenter will be returned, followed by a prompt to enter the VM name you wish to modify. Once the VM name is entered a list of all the MS Windows Ethernet interfaces and their respective configurations shall be returned:
Provide the required IP configuration updates for the interface specified (‘Ethernet 2’ in this example):
Specify whether you wish to modify the DNS entries:
The script utilizes the Invoke-VMScript option to run Windows ‘Netsh’ commands on the network interface (Modify the script with your Windows username and password). These are the results as per the example given, along with the option to repeat the same process for another Windows Guest VM:
SCRIPT IN FULL:
##########################################################
#
# Reference: MS Windows Guest IP Modification
# Script: PowerCLI IP&DNS Modification
#
# Date: 2015-04-21
#
# Version 1.0
#
##########################################################
Write-Host "Please enter the ESXi/Vcenter Host IP Address:" -ForegroundColor Yellow -NoNewline
$VMHost = Read-Host
Write-Host "Please enter the ESXi/Vcenter Username:" -ForegroundColor Yellow -NoNewline
$User = Read-Host
Write-Host "Please enter the ESXi/Vcenter Password:" -ForegroundColor Yellow -NoNewline
$Pass = Read-Host
#Prompt for VM name
Write-Host "Please enter the VM Name that requires IP modification:" -ForegroundColor Yellow -NoNewline
$VM = Read-Host
Write-Host "The current VM Network Configuration:" -ForegroundColor Yellow
#Display Existing NIC Configuration
$shownet = "netsh interface ip show config"
Invoke-VMScript -ScriptText $shownet -VM $vm -GuestUser administrator -GuestPassword MSPassword -ScriptType Bat
################################
# Modify IP Configuration? y/n #
################################
Write-Host "Modify IP Details? " -ForegroundColor Yellow -NoNewline
Write-Host " Y/N:" -ForegroundColor Red -NoNewline
$IPChange = Read-Host
if ($IPChange -eq "y") {
Write-Host "Please provide the following IP details:" -ForegroundColor Yellow
#Prompt for IP Updates:
Write-Host "Interface Name:" -ForegroundColor Green -NoNewline
$NIC = Read-Host
Write-Host "New IP address:" -ForegroundColor Green -NoNewline
$IP = Read-Host
Write-Host "New Netmask:" -ForegroundColor Green -NoNewline
$NETMASK = Read-Host
Write-Host "New Gateway:" -ForegroundColor Green -NoNewline
$Gateway = Read-Host
#Invoke Windows netsh Script
$script = "netsh interface ip set address ""$NIC"" static $IP $NETMASK $Gateway"
Invoke-VMScript -ScriptText $script -VM $vm -GuestUser administrator -GuestPassword MSPassword -ScriptType Bat
}
#################################
# Modify DNS Configuration? y/n #
#################################
Write-Host "Modify DNS Details? " -ForegroundColor Yellow -NoNewline
Write-Host " Y/N:" -ForegroundColor Red -NoNewline
$DNSChange = Read-Host
if ($DNSChange -eq "y") {
#Prompt for Primary DNS IP:
Write-Host "Enter Primary DNS IP:" -ForegroundColor Green -NoNewline
$DNS1 = Read-Host
Write-Host "Enter Secondary DNS IP:" -ForegroundColor Green -NoNewline
$DNS2 = Read-Host
$DNSPrimary = "netsh interface ip set dnsservers name=""$NIC"" static $DNS1"
Invoke-VMScript -ScriptText $DNSPrimary -VM $vm -GuestUser administrator -GuestPassword MSPassword -ScriptType Bat
Write-Host "Change IP Configuration for another WINDOWS Guest VM? " -ForegroundColor Yellow -NoNewline
Write-Host " Y/N:" -ForegroundColor Red -NoNewline
$response = Read-Host
}
while ($response -eq "Y")
Thanks @CliffCahill and ‘Mike Leahy’ for your input, as always greatly appreciated!
i am executing same ps1 command using different local admin user, but having an error, like..
ScriptOutput : The requested operation requires elevation (Run as administrator).
any idea about work around.
same local admin having full admin rights.
i don’t want to go through with built in admin.
Hi, have you modified the script to change the administrator: Invoke-VMScript -ScriptText $shownet -VM $vm -GuestUser administrator -GuestPassword MSPassword -ScriptType Bat
HI, Thanks for answering.
unfortunately, still having same problem, no luck with your command.
Hi,
i am executing same ps1 command using different local admin user, but having an error, like..
ScriptOutput : The requested operation requires elevation (Run as administrator).
any idea about work around.
same local admin having full admin rights.
i don’t want to go through with built in admin.
Hi, have you modified the script to change the administrator: Invoke-VMScript -ScriptText $shownet -VM $vm -GuestUser administrator -GuestPassword MSPassword -ScriptType Bat
HI, Thanks for answering.
unfortunately, still having same problem, no luck with your command.
Thanks