Hello team
i'm unable to get task progress(e.g progress percentage, state, etc..) when shutdown bulk of vms and get a following error :
### Error output ###
Index operation failed; the array index evaluated to null.
At line:10 char:5
+ $taskTab[(Shutdown-VMGuest -vm $_ -Confirm:$false).id] = $_.name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
### End of error output ###
### Findings ###
#1 there is no 'id' property for (Shutdown-VMGuest -vm $_ -Confirm:$false)
#2 Tried property (id, uid, vmid and VM) for (Shutdown-VMGuest -vm $_ -Confirm:$false), but it does not return a taskid so if/elseif never get evalutated
how to bind (Shutdown-VMGuest -vm $_ -Confirm:$false).property with taskid ?
note: new-snapshot id property auto-bind with taskid, but id property not work for shutdown-vmguest and start-vm : either it not have ID property or return value like this : 3b51542f-69f3-4341-bf2e-a4508bdc2a5f rather than shutdown taskid: Task-task-29072
***
I think the issue is on this command but not sure how to fix it:
***
##member of variable (Shutdown-VMGuest -vm $_ -Confirm:$false):
ConvertToVersion Method T ConvertToVersion[T](), T VersionedObjectInterop.ConvertToVersion[T]()
Equals Method bool Equals(System.Object obj)
GetClient Method VMware.VimAutomation.ViCore.Interop.V1.VIAutomation VIObjectCoreInterop.GetClient()
GetHashCode Method int GetHashCode()
GetType Method type GetType()
IsConvertableTo Method bool IsConvertableTo(type toType), bool VersionedObjectInterop.IsConvertableTo(type type)
LockUpdates Method void ExtensionData.LockUpdates()
ToString Method string ToString()
UnlockUpdates Method void ExtensionData.UnlockUpdates()
ConfiguredGuestId Property string ConfiguredGuestId {get;}
Disks Property VMware.VimAutomation.ViCore.Types.V1.VM.Guest.DiskInfo[] Disks {get;}
ExtensionData Property System.Object ExtensionData {get;}
GuestFamily Property string GuestFamily {get;}
GuestId Property string GuestId {get;}
HostName Property string HostName {get;}
IPAddress Property string[] IPAddress {get;}
Nics Property VMware.VimAutomation.ViCore.Types.V1.VM.Guest.NicInfo[] Nics {get;}
OSFullName Property string OSFullName {get;}
RuntimeGuestId Property string RuntimeGuestId {get;}
ScreenDimensions Property System.Nullable[System.Drawing.Size] ScreenDimensions {get;}
State Property VMware.VimAutomation.ViCore.Types.V1.VM.Guest.GuestState State {get;}
ToolsVersion Property string ToolsVersion {get;}
Uid Property string Uid {get;}
VM Property VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine VM {get;}
VmId Property string VmId {get;}
VmName Property string VmName {get;}
VmUid Property string VmUid {get;}
### shutdown Script###
PowerCLI uses 2 types of Task objects, server-side and client-side.
In short, meaning where the background Task is executed.
Shutdown-VMGuest is one of those generating a client-side Task, hence no Id.
You should see the Task with a Get-Task cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI uses 2 types of Task objects, server-side and client-side.
In short, meaning where the background Task is executed.
Shutdown-VMGuest is one of those generating a client-side Task, hence no Id.
You should see the Task with a Get-Task cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD thank you
since multiple VMs shutdown simultaneously , so how to make each shutdown process associate with its own task (get-task)?
I think I found a way to get the status for multiple VMs when shutdown them simultaneously by following this article
I will run few more tests and update outcomes
both Shutdown-VMGuest and start-up work now
but Shutdown-VMGuest 'state' keeps showing in 'running' and even though VM already powered off.
PS C:\Windows\system32> $v3 | select state, vm
State VM
----- --
Running CASP-WS1
Running CASP-CV-VMwareVSA
If run this command "$v3 | foreach { $_.vm }" and it shows VM PowerState: PoweredOff.
however state and $v3.extensiondata still show running, does this expected behavior ?
####1 Shutdown-VMGuest script###
$VMpath = get-content "C:\temp\vms.txt"
$vmlist = get-vm | where {$_.name -in $VMpath}
$v3 = @()
$vmlist | ForEach-Object -Process {
$v3 += (Shutdown-VMGuest -vm $_ -Confirm:$false )
}
$runningTasks = $v3.Count
while($runningTasks -gt 0){
$v3 | foreach {
if ($_.vm.powerstate -eq "PoweredOff"){
$_.vm
$runningTasks--
}
}
}
### end of shutdown-vmguest script###
#2 start-up works now
### Start-Up script ###
### End of Start-Up script ###
You could try to run an UpdateViewData() call before checking the values
$v3.extensiondata | %{ $_.UpdateViewData()}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD thanks
$v3.extensiondata | %{ $_.UpdateViewData()}
$v3 doesn't has a method - updateviewdata()
I tried a different way and it works now
could you please take a look and let me know if there is anything need to be improved, thanks
###ShutDown Bulk VMs###