VMware Cloud Community
JoergenKaare
Contributor
Contributor

get-task -id always return Object Reference not swt to an instance of an object

Get-task -id <someid> returns the task but also the errormessage.

 

PS C:\WINDOWS\system32> get-task -id Task-task-4725953
get-task : 28-01-2021 13:05:43 Get-Task Object reference not set to an instance of an object.
At line:1 char:1
+ get-task -id Task-task-4725953
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Task], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.Common.Commands.Cmdlets.GetTask

Name State % Complete Start Time Finish Time
---- ----- ---------- ---------- -----------
RemoveSnapshot_Task Success 100 01:03:29 01:03:45

Using latest 12.1 powercli

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

I suspect you might be connected to more than 1 vSphere server.
The error might come from the vSphere server where this Task is not known.

Check what is in $global:defaultVIServers


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
JoergenKaare
Contributor
Contributor

No- we only have one vCenter.

 

Changing the statement to Get-task | where {$_.id -eq <taskname> } make it work without error

Reply
0 Kudos
LucD
Leadership
Leadership

Can you stop/start your PowerShell session?
It might be a corruption in the PS session.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
JoergenKaare
Contributor
Contributor

Oh, yes - I have seen that before - will check it later.

Reply
0 Kudos
JoergenKaare
Contributor
Contributor

After at powershell restart problem solved - both methods works. Thanks for your assist.

JoergenKaare_0-1611844733966.png

 

Reply
0 Kudos