VMware Cloud Community
binoche
VMware Employee
VMware Employee
Jump to solution

how to catch exception after ReconfigVM_Task?

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
5 Replies
binoche
VMware Employee
VMware Employee
Jump to solution

Try { $vmview.ReconfigVM($spec)}

Catch{$_.exception.message}

it can print the exception message, but how ReconfigVM_Task can?

Simon

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
binoche
VMware Employee
VMware Employee
Jump to solution

thank you Sir,

right, I can keep watching this task, but does it mean we are unable to catch this type of exception?

Simon

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
binoche
VMware Employee
VMware Employee
Jump to solution

got it, thank you Sir

Simon

0 Kudos