We have a bunch of machines using E1000 vNIC and we need to upgrade them to vmxnet3. I deployed two test VMs and attempted to use VMupgradehelper.bat /s to save the network settings then shut down and upgrade the adapter with "PowerCLI C:\> get-vm dhdvutst01 | Get-NetworkAdapter | set-networkadapter -type vmxnet3" Then boot the server back up and run vmupgradehelper.bat /r to restore the network settings. This is not work. I do not get an error and none of the IP settings get set. This particular test is being done on ESX 6.0 VM Version 11 vm tools version 10240 and the VM in question is Windows Server 2012 R2.
Which VMUpgradeHelper.bat is that?
The one I know (from KB1015572), only states support till ESXi 5.0
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Its just what is in the VM tools folder. I assume it was installed with the VM Tools version 10240 which is the current version according to vcenter.
If it is not supported anymore what is the replacement method or process to get this done? Do I have to write a script instead?
Should be possible by using the Invoke-VMScript cmdlet.
The GetVmGuestNetworkInterface and SetVMGuestNetworkInterface show one way of doing it.
They use ipconfig to extract the settings and netsh to configure the settings.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah I found this script but I was hoping there was an easier way.
$vcenter = "x.x.x.x"
$SNM = "255.255.255.0"
$GW = "x.x.x.x"
$dns1 = "x.x.x.x"
$dns2 = "x.x.x.x"
# Define the functions to set IP,SNM, and GW
Function Set-WinVMIP ($VM, $IP, $SNM, $GW){
Invoke-VMScript -VM $VM -GuestUser administrator -GuestPassword 'xxxxx' -ScriptType bat -ScriptText ipconfig | select-string -pattern "Local Area Connection[ ]?[\d]*" | % { $_.Matches } | % {$_.Value} | new-variable LAC
$LAC1 = $LAC -replace ".$"
$LAC2 = '"' + $LAC1 + '"'
$netsh = "c:\windows\system32\netsh.exe interface ip set address $LAC2 static $IP $SNM $GW 1"
Write-Host "Setting IP address for $VM..."
Invoke-VMScript -VM $VM -GuestUser administrator -GuestPassword 'xxxxxx' -ScriptType bat -ScriptText $netsh
Write-Host "Setting IP address completed."
}
Connect-VIServer $vcenter
foreach ($_.VMname in (Import-Csv "$ENV:USERPROFILE\desktop\vm-ip.csv" -UseCulture) ) {
$VM = Get-VM $_.VMname
Set-WinVMIP $VM -GuestUser administrator -GuestPassword 'xxxxxx' $_.IP $SNM $GW
}
No, that seems to be the easiest way afaik
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So the script doesn't quite work because the servers are a mix of 2008 and 2012. The network interface name is Local Area Connection X on Server 2008 and on 2012 They are named Ethernet X. So I tried to modify the script to account for this but I can't get it to work. So I am trying to get the OS version and then run commands based on that but it gets the following error.
"Could not compare "Unexpected token '.7601' in expression or statement.
At line:1 char:12
+ & {6.1.7601 <<<< }
+ CategoryInfo : ParserError: (.7601:String) [], ParentContainsEr
rorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
" to "6.2". Error: "Cannot convert the "6.2" value of type "System.String" to
type "VMware.VimAutomation.ViCore.Impl.V1.VM.Guest.VMScriptResultImpl"."
At C:\scripts\SetWinVMIP_Draft2.ps1:12 char:8
+ if($osversion -gt "6.2")
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : ComparisonFailure"
The value of (Get-WmiObject win32_operatingsystem).version is 6.1.7601 and apparently it thinks its an expression.
I tried the following so I wouldnt have to determine OS version or any of that but since all the servers have varying versions of powershell installed which is out of my control it doesnt work if the version is not 3 or newer.
Invoke-VMScript -VM $VM -GuestCredential $credentials -ScriptType powershell (gwmi win32_networkadapter |?{$_.adaptertype -match "ethernet"}).netconnectionid[0] | new-variable adapter
Here is the script I am currently working with.
--------------------------------------
# Define the function to set IP,SNM, and GW
Function Set-WinVMIP ($VM, $IP, $SNM, $GW){
$credentials = Get-Credential
#Determine OS
Invoke-VMScript -VM $VM -GuestCredential $credentials -ScriptType powershell -ScriptText (Get-WmiObject win32_operatingsystem).version | New-Variable osversion
if($osversion -gt "6.2")
{
#Perform Server 2012 stuff
Invoke-VMScript -VM $VM -GuestCredential $credentials -ScriptType bat -ScriptText ipconfig | select-string -pattern "Ethernet[ ]?[\d]*" | % { $_.Matches } | % {$_.Value} | new-variable LAC
$LAC1 = $LAC -replace ".$"
$LAC2 = '"' + $LAC1 + '"'
$netsh = "c:\windows\system32\netsh.exe interface ip set address $LAC2 static $IP $SNM $GW 1"
Write-Host "Setting IP address for $VM..."
Invoke-VMScript -VM $VM -GuestUser $credentials -ScriptType bat -ScriptText $netsh
Write-Host "Setting IP address completed."
}
else
{
#Do server 2008 stuff
Invoke-VMScript -VM $VM -GuestUser $credentials -ScriptType bat -ScriptText ipconfig | select-string -pattern "Local Area Connection[ ]?[\d]*" | % { $_.Matches } | % {$_.Value} | new-variable LAC
#$LAC1 = $LAC -replace ".$"
$LAC2 = '"' + $LAC + '"'
write-host $LAC2
$netsh = "c:\windows\system32\netsh.exe interface ip set address $LAC2 static $IP $SNM $GW 1"
Write-Host "Setting IP address for $VM..."
Invoke-VMScript -VM $VM -GuestUser $credentials -ScriptType bat -ScriptText $netsh
Write-Host "Setting IP address completed."
}
}
# Path to csv file that contains the VMs and the IP settings
$path = "c:\temp\vm-ip.csv"
$csv = Import-Csv -path $path
foreach ($record in $csv)
{
$VM = Get-VM $record.VMname
$SNM = $record.subnet
$GW = $record.gateway
$IP = $record.IP
#Set-WinVMIP $VM $record.IP $SNM $GW
Set-WinVMIP $VM $IP $SNM $GW
}