Hi Guru,
I was using ReconfigVM_Task to reconfigure my vm, this task will be running in the background but frequently it could be exception at once, but I was not been informed in the console,
I wish I can print such as what type exception in the console, do you know how I should do? many thanks
Simon
If you mean with a Try-Catch construct, yes, I'm afraid so.
Do not forget that the Task object you have in PowerCLI is a read-only copy of the vSphere Task object.
You have to use the UpdateViewData method to refresh the content.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try { $vmview.ReconfigVM($spec)}
Catch{$_.exception.message}
it can print the exception message, but how ReconfigVM_Task can?
Simon
You can check the Task.Info.Error property.
Something like this
$waitTaskStates = [VMware.Vim.TaskInfoState]::queued,[VMware.Vim.TaskInfoState]::running
$taskMoRef = $vm.ReconfigVM_Task($spec)
$task = Get-View -Id $taskMoRef
while($waitTaskState -contains $task.Info.State){
sleep 1
$task.UpdateViewData('Info.State')
}
if($task.Info.State -ne 'Success'){
$task.UpdateViewData('Info.Error')
Write-Host "Task had an error"
Write-Host "`tFault: $($task.Info.Error.Fault)"
Write-Host "`tFault: $($task.Info.Error.LocalizedMessage)"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank you Sir,
right, I can keep watching this task, but does it mean we are unable to catch this type of exception?
Simon
If you mean with a Try-Catch construct, yes, I'm afraid so.
Do not forget that the Task object you have in PowerCLI is a read-only copy of the vSphere Task object.
You have to use the UpdateViewData method to refresh the content.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
got it, thank you Sir
Simon