We are using vSphere 6.7 in our environment.
I am writing a script to look for certain tasks associated with specific target resources in our vCenter environment. However, Get-Task
only returns recent tasks that show up in the Recent Tasks
view in the HTML5 client. I can get events associated with resources just fine, for example I can get the events associated with a given datastore folder like so:
Get-Folder FOLDER_NAME -Type Datastore | Get-VIEvent
But there doesn't seem to be an equivalent way to get tasks associated with those same resources. Get-Task
doesn't accept pipeline input in the same way Get-VIEvent
does, and results in an error:
Get-Folder FOLDER_NAME -Type Datastore | Get-Task
Output:
Get-Task: The input object cannot be bound to any parameters for the command either
because the command does not take pipeline input or the input and its properties
do not match any of the parameters that take pipeline input.
Get-Task
also doesn't show any tasks that don't show in the Recent Tasks
view of the HTML5 client.
Inspecting the object doesn't seem to offer any members that let me see tasks targeting these resources:
Get-Folder FOLDER_NAME -Type Datastore | Get-Member
Output:
TypeName: VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.DatastoreClusterImpl
Name MemberType Definition
---- ---------- ----------
ConvertToVersion Method 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 VersionedObjectInterop.IsConvertableTo(type type)
LockUpdates Method void ExtensionData.LockUpdates()
ToString Method string ToString()
UnlockUpdates Method void ExtensionData.UnlockUpdates()
CapacityGB Property decimal CapacityGB {get;}
ExtensionData Property System.Object ExtensionData {get;}
FreeSpaceGB Property decimal FreeSpaceGB {get;}
Id Property string Id {get;}
IOLatencyThresholdMillisecond Property System.Nullable[int] IOLatencyThresholdMillisecond {get;}
IOLoadBalanceEnabled Property bool IOLoadBalanceEnabled {get;}
Name Property string Name {get;}
SdrsAutomationLevel Property VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsAutomationLevel SdrsAutomationLevel {get;}
SpaceUtilizationThresholdPercent Property System.Nullable[int] SpaceUtilizationThresholdPercent {get;}
Uid Property string Uid {get;}
This isn't just for folder tasks, though, I can't seem to enumerate any tasks for a given resource at all if they aren't in the Recent Tasks
view of the HTML5 client. Conversely, in the HTML5 client, I can easily enumerate tasks on a given resource using its Monitor
tab, but this doesn't help with automation short of crawling through the UI programmatically (not happening):
How do I use PowerCLI to see the tasks targeting specific resources using PowerCLI?