Hello,
I have some VM with Old Version (Get-VM | Select Name, Version)
v7, v8 and v9
I would like to upgrade Version with powershell script from a csv list, like machine who have version 7 upgrade to 8.
Thanks
Have a look on this... upgrade vm hardware and tools with one script
You can skip tools part if dont want to upgrade tools.
Try like this.
It will upgrade the HW version to v8 of all VMs that are currently at v7.
Note that the VM will need a power off/poweron to actually update the HW version.
foreach($vmRow in Import-Csv vm.csv -UseCulture){
$vm = Get-VM -Name $vmRow.Name
if($vm.Version -eq [VMware.VimAutomation.ViCore.Types.V1.VM.VMVersion]::v7){
Set-VM -VM $vm -Version ([VMware.VimAutomation.ViCore.Types.V1.VM.VMVersion]::v8)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello
So i tried that out like you wrote "You can skip tools part if dont want to upgrade tools."
But it only works up to vmversion 10 (v10).
When i try a never version (13) the script fail with error message "The operation is not supported on the object".
Im using esxi 6.5 and vms are updated manually to v13 outside of the script.
Any ideas?
Import-Csv C:\xxx\xxx\\xx -UseCulture |
%{
$vm = Get-VM $_.Name
$poweredOn = $false
if($vm.PowerState -ne 'PoweredOff'){
$poweredOn = $true
Stop-VM -VM $vm -Confirm:$false
}
Set-VM -VM $vm -Version ([VMware.VimAutomation.ViCore.Types.V1.VM.VMVersion]::v12) -Confirm:$false
if($poweredOn){
Start-VM -VM $vm -Confirm:$false
}
}
Which PowerCLI version are you using?
Only the recent version have the v13 option.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello
Thanks for the stick reply lucd.
Usling version 6.5.0 r1.
Best regards
D
When you type in Code or the ISE the 'Set-VM -Version ' and then <Ctrl>-<Space> which options does intellisense show you?
Is v12 included?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD.
Yepp, v12 is included also v13 and v11.
Best Regards
Daniel
Is that VM running on an ESXi node that has the correct version for v12 HW?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello
Yes the esxi version is 6.5 update1.
Do you maybe have another script for update of hw from a csv file that i can try out?
Best Regards
Daniel
Well, the code I posted earlier in this thread is rather basic, there isn't much variation possible.
But could you try the following with one of the VMs that fail (make sure it is powered off).
And attach the output.
$vmName = '<failing-vm-name>'
$vm = Get-VM -Name $vmName
$vm | Select Name,Version,
@{N='VMHost';E={$_.VMHost.Name}},
@{N='VMHost-Version';E={"$($_.VMHost.Version)-$($_.VMHost.Build)"}}
Set-VM -VM $vm -Version v12 -Confirm:$false -Verbose
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello
Thanks, i will try this out next week.
I will give you an update how i worked.
Best Regards
Daniel
Hello LucD
So i tried out the command but i didn't worked.
Output error message..
"
VMNAME(example) v10 hostname(example) 6.5.0-7388607
Set-VM : 2018-03-05 09:36:37 Set-VM The operation for the entity "VMNAME(example)" failed with the following message: "The operation is not supported on the object."
At C:\Temp\powercli\Vmtools\Test\updatehardwarenocsv.ps1:7 char:1
+ Set-VM -VM $vm -Version v12 -Confirm:$false -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VM], NotSupported
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM
"
Best Regards
D
What is the version of your vCenter?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD
The host is a "stand alone" host right now without connection to a vcenter.
I Just want to test the script out first before i run them in production enviroment.
/ D
Are the VMware Tools on that VM up to date?
You will have to update those first, see KB1010675.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD
So i found another thread regarding problems with set-vm cmdlets.
So i removed the msi powercli and added modules to powershell and now the script workes, Thanks!
Another thing though...
I tried the shutdown-vmguest in the script (i don't want a "hard poweroff" because of DB servers) but that didn't work out.
Do you have any ideas on this?
Thanks for your awesome help!
/ D
What exactly didn't work out?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello
So the script looks like this.
Import-Csv C:\csv-export.csv -UseCulture |
where{$_.ToolStatus -ne [VMware.Vim.VirtualMachineToolsStatus]::toolsOk} | %{
$vm = Get-VM $_.Name
Update-Tools -VM $vm -NoReboot
$poweredOn = $false
if($vm.PowerState -ne 'PoweredOff'){
$poweredOn = $true
Stop-VMGuest -VM $vm -Confirm:$false
}
Set-VM -VM $vm -Version ([VMware.VimAutomation.ViCore.Types.V1.VM.VMVersion]::v13) -Confirm:$false
if($poweredOn){
Start-VM -VM $vm -Confirm:$false
}
}
And the error output is this
State IPAddress OSFullName
----- --------- ----------
ShuttingDown {169.254.3.24, 17... Microsoft Windows Server 2016 (64-bit)
Set-VM : 2018-03-05 13:11:57 Set-VM The operation for the entity "vmexemple" failed with the following message: "The operation is not allowed in the current state.
"
At C:\toolandhardware.ps1:19 char:5
+ Set-VM -VM $vm -Version ([VMware.VimAutomation.ViCore.Types.V1.VM ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VM], InvalidState
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM
Start-VM : 2018-03-05 13:11:57 Start-VM The operation for the entity "vmexemple" failed with the following message: "The attempted operation cannot be performe
d in the curre
nt state (Powered on)."
At C:\toolandhardware.ps1:23 char:9
+ Start-VM -VM $vm -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-VM], InvalidPowerState
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.StartVM
So what i can think of is that i tries to run hw update and power on before the server is poweroff (checked task log on the esxi host)
Any ideas?
/ Daniel
The Stop-VMGuest cmdlet will ask the guest OS to shutdown, but once that is done, it returns and the script continues.
The best option would be to built in a loop where the script waits till the VM is actually powered off.
Something like this
Stop-VMGuest -VM $vm -Confirm:$false
while($vm.PowerState -ne 'PoweredOff'){
sleep 10
$vm = Get-VM -Name $vm.Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference