Hello Everyone,
I'm looking to schedule the Bulk lists of VM's to upgrade HW version at a particular time through power cli. Kindly help.
thanks
vmk2014
LucD,
Thanks for finding. Now slight improvement now but error shows
PS C:\> cd temp
PS C:\temp> .\VM-HW.ps1
State IPAddress OSFullName
----- --------- ----------
Running {2002:9f6c:23b9::... Microsoft Windows Server 2008 R2 (64-bit)
Shutdown-VMGuest : 12/04/2018 12:14:12 AM Stop-VMGuest Operation "Shutdown VM guest." failed for VM "cb
vwt-iimss18d"
for the following reason: Cannot complete operation because VMware Tools is not running in this virtual machine.
At C:\temp\VM-HW.ps1:9 char:25
+ Get-VM -Name $vmNames | Shutdown-VMGuest -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Stop-VMGuest], VimException
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_ShutdownVmGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.
Commands.StopVmGuest
Running {159.108.37.178, ... Microsoft Windows Server 2012 (64-bit)
Shutdown-VMGuest : 12/04/2018 12:14:12 AM Stop-VMGuest Operation "Shutdown VM guest." failed for VM "cb
vwt-iimss17d"
for the following reason: Cannot complete operation because VMware Tools is not running in this virtual machine.
At C:\temp\VM-HW.ps1:9 char:25
+ Get-VM -Name $vmNames | Shutdown-VMGuest -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Stop-VMGuest], VimException
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_ShutdownVmGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.
Commands.StopVmGuest
Thanks
vmk
LucD,
I believe, if the VMware tools is not installed or out of date then the script will not work. Can we put clause that if vmware tools not installed or out of date then it will install first and then update
VM HW versions.
Thanks
vmk
Yes, to use the *Guest cmdlets, you need the VMware Tools to be installed.
Updating the VMware Tools is builtin, installing from scratch requires more.
Which types of guest OS are we looking at?
A mix of Windows and Linux?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
It's upgrading HW to 13, but with error on the screen. Can we remove the below error.
PS C:\temp> .\VM-HW.ps1
State IPAddress OSFullName
----- --------- ----------
Running {150.x.x.121, ... Microsoft Windows Server 2012 (64-bit)
Running {150.x.x.119, ... Microsoft Windows Server 2012 (64-bit)
Get-VM : 12/04/2018 12:43:56 AM Get-VM VM with name '#cxv-txm1d' was not found using the specified filter(s).
At C:\temp\VM-HW.ps1:9 char:1
+ Get-VM -Name $vmNames | Shutdown-VMGuest -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:56 AM Get-VM VM with name '#VM4' was not found using the specified filter(s
).
At C:\temp\VM-HW.ps1:9 char:1
+ Get-VM -Name $vmNames | Shutdown-VMGuest -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:56 AM Get-VM VM with name '#VM5' was not found using the specified filter(
s).
At C:\temp\VM-HW.ps1:9 char:1
+ Get-VM -Name $vmNames | Shutdown-VMGuest -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:56 AM Get-VM VM with name '#VM3' was not found using the specified filter(
s).
At C:\temp\VM-HW.ps1:9 char:1
+ Get-VM -Name $vmNames | Shutdown-VMGuest -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:58 AM Get-VM VM with name 'cxv-txm1d' was not found using the specified filter(s).
At C:\temp\VM-HW.ps1:15 char:8
+ while((Get-VM -Name $vmNames | Select -ExpandProperty PowerState) -co ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:58 AM Get-VM VM with name '#VM2' was not found using the specified filter(s
).
At C:\temp\VM-HW.ps1:15 char:8
+ while((Get-VM -Name $vmNames | Select -ExpandProperty PowerState) -co ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:58 AM Get-VM VM with name '#cbvwt-iimxyzd' was not found using the specified filter(
s).
At C:\temp\VM-HW.ps1:15 char:8
+ while((Get-VM -Name $vmNames | Select -ExpandProperty PowerState) -co ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:43:58 AM Get-VM VM with name '#cbvwt-iimxyz9d' was not found using the specified filter(
s).
At C:\temp\VM-HW.ps1:15 char:8
+ while((Get-VM -Name $vmNames | Select -ExpandProperty PowerState) -co ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:44:05 AM Get-VM VM with name '#cbx-txm1d' was not found using the specified filter(s).
At C:\temp\VM-HW.ps1:15 char:8
+ while((Get-VM -Name $vmNames | Select -ExpandProperty PowerState) -co ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:44:05 AM Get-VM VM with name 'cbvwt-iimxy10d' was not found using the specified filter(s
).
At C:\temp\VM-HW.ps1:15 char:8
+ while((Get-VM -Name $vmNames | Select -ExpandProperty PowerState) -co ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 12/04/2018 12:44:05 AM Get-VM VM with name 'ccbvwt-iimxy10d' was not found using the specified filter(
s).
thanks
vmk
LucD,
Please find my answer
Yes, to use the *Guest cmdlets, you need the VMware Tools to be installed.- Understood, that it require vmware tools inorder to cmdlet function to work
Updating the VMware Tools is builtin, installing from scratch requires more. Can we ignore and proceed further if the script finds VMware tools missing or not installed.
Which types of guest OS are we looking at? Only Windows 2008,2012 and 2016
A mix of Windows and Linux? Only Windows 2008,2012 and 2016
Thanks
vmk
It looks as if for a number of the names in the CSV, the VM can not be found.
Are you connected to a vCenter?
Did you check if the names are correct?
Does a Get-VM work for all the names in the list?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
All VM's names are correct, just i tweaked it in post in order to hide the VM's name.
Also, does the script will work if the VMware tools is out of date ? Please confirm or only if the VMware tools is not installed it will not work.
Thanks
vmk
Sorry, i missed out to answer last questions. Does a Get-VM work for all the names in the list?
PS C:\temp>
PS C:\temp> Get-VM VM1
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
VM1 PoweredOn 2 4.000
PS C:\temp> Get-VM VM2
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
VM2 PoweredOn 2 4.000
Thanks
vmk
That is not what the errors are saying.
They clearly state that the VMs with those names are not found.
You can check again with
$vmNames = Get-Content -Path C:\TEMP\vmliste.txt | where{$_ -ne ''}
Get-VM -Name $vmNames
When the VMware Tools are out of date, but running, the Shutdown-VMGuest should work.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are right one of the VM's was incorrect or not able to find not sure hwy but its in VC.
PS C:\temp> .\test.ps1
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
VM1 PoweredOn 2 4.000
VM2 PoweredOn 2 4.000
This version of the script should only shut down powered on VMs that have the VMware Tools installed.
Then for all powered off VMs the HW version is upgraded.
$vmNames = Get-Content -Path C:\TEMP\vmliste.txt | where{$_ -ne ''}
# Select powered off VM and powered on VMs that have VMware Tools running
$vms = Get-VM -Name $vmNames | where{$_.PowerState -eq 'PoweredOff' -or
($_.PowerState -eq 'PoweredOn' -and $_.Guest.State -eq 'running')}
# Shutdown all powered on VMs from list
$vms | where{$_.PowerState -eq 'PoweredOn'} | Shutdown-VMGuest -Confirm:$false
# Wait till all VMs are shutdown
while((Get-VM -Name $vms.Name | Select -ExpandProperty PowerState) -contains 'PoweredOn'){
sleep 5
}
# Set new HW version and start VM
Get-VM -Name $vms.Name | Set-VM -Version v13 -Confirm:$false | Start-VM -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Sorry this script
powered off VM's didnt powered on and powered on shutdown but never powered on again while upgrade.
Fianlly, both the VM's remain poweredoff. I selected 2 test VM's
PS C:\temp> .\VM-HW2.ps1
State IPAddress OSFullName
----- --------- ----------
Running {150.x.x.122, ... Microsoft Windows Server 2012 (64-bit)
thanks
vmk
So you used 2 VMs?
You are sure neither of these was at HW version 13?
One powered on and one powered off, is that correct?
Was the powered on VM powered off?
Did the HW version change?
But the Start-VM at the end did work?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So you used 2 VMs? - Yes
You are sure neither of these was at HW version 13? yes they were version 8, hence i tried to update
One powered on and one powered off, is that correct? Yes, one powered off and one powered on
Was the powered on VM powered off? yes
Did the HW version change? No
But the Start-VM at the end did work?
my mistake, apologies. I didn't copied last line of the script.
thanks
vmk
Ok, thanks.
So the only thing missing is the upgrade to HW version 13?
Do you see any errors in the events when the Set-VM is executed?
Can you try with one specific VM that is not yet on v13 and that is powered off?
With
Get-VM -Name xyz | Set-VM -Version v13 -Confirm:$false
Btw, which version of PowerCLI are you using?
Older PowerCLI versions do not yet have the v13 option available on the Version parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, inf act, i don't have any powered off test VM's, hence i powered off one of the running VM and executed the cLI
Set-VM -Name cwv-ctxpvs2t | Set-VM -Version v13 -Confirm:$false
PS C:\temp> Set-VM -Name cyv-ctxyvs2t | Set-VM -Version v13 -Confirm:$false
Set-VM : 12/04/2018 4:21:53 AM Set-VM Value cannot be found for the mandatory parameter VM
At line:1 char:1
+ Set-VM -Name cyv-ctxyvs2t | Set-VM -Version v13 -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM
PS C:\temp> Get-PowerCLIVersion
WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.
PowerCLI Version
----------------
VMware PowerCLI 11.0.0 build 10380590
---------------
The 1st cmdlet is a Get-VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, typo erro. please find now
S C:\temp> Get-VM -Name cxv-ctxyvs2t | Set-VM -Version v13 -Confirm:$false
et-VM : 12/04/2018 4:32:08 AM Set-VM Server task failed: The operation is not supported on the object.
t line:1 char:29
Get-VM -Name cxv-ctxyvs2 | Set-VM -Version v13 -Confirm:$false
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VM], ViError
+ FullyQualifiedErrorId : Client20_VMServiceImpl_UpdateVM_UpgradeVM_ViError,VMware.VimAutomation.ViCore.Cmdlets.Co
mmands.SetVM
That message could indicate a couple of things:
Can you try the same line, but use V9 or V10 for the Version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
The VM is running on ESXI5.5.
VMware ESXi, 5.5.0, 7967571
thanks
vmk