Unable to Delete Resources: There is currently an active background action

An addition to CTX138318 about how to delete an old Citrix Studio Hosting connection.
Instead of deleting every task manually we make use of PowerShell piping and Out-GridView.

Today in Citrix Studio I discovered a dead Hosting connection I set up years ago for some MCS tests. When I tried to simply delete the connection, I received the following message:

The error message leads to the following (helpful!) KB article: CTX138318

After following the different steps outlined in the article …

asnp citrix*
Cd XDHyp:\HostingUnits
Get-ChildItem
Get-ProvTask | Where-Object { $_.ImagesToDelete | Where-Object { $_.HostingUnit -eq "f4dcd282-3d9b-478a-9107-2cafe6f6f124" } }

… I ended up with something like this:

TaskId                 : db2ed90d-9f5f-43c9-8ee0-01dfde159544
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 28.05.2018 22:47:27
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 28.05.2018 22:47:37
ActiveElapsedTime      : 9
DateFinished           : 28.05.2018 22:47:37
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/28/2018 6:59:24 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/28/2018 7:02:31 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 10f7b103-0675-42c8-9a97-0c20016af145
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 14.04.2018 21:10:39
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 02:59:26
ActiveElapsedTime      : 5464104
DateFinished           : 17.06.2018 02:59:26
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/16/2018 11:01:05 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/16/2018 11:04:12 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 0d3bbe35-581d-46c8-b85f-23aa9911ed6f
Active                 : True
Host                   : XA-WMS2016-01
DateStarted            : 17.06.2018 02:59:10
Metadata               : {}
CurrentOperation       : Running
TaskProgress           : 
LastUpdateTime         : 18.06.2018 17:05:10
ActiveElapsedTime      : 137155
DateFinished           : 
TerminatingError       : 
Type                   : DisusedImageCleanUp
Status                 : Running
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/18/2018 12:02:03 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/18/2018 12:05:09 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Running
TaskExpectedCompletion : 

TaskId                 : 210c7daf-ed26-4275-8cab-26dee5f941e7
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 15.04.2018 11:20:05
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 15.04.2018 11:20:35
ActiveElapsedTime      : 29
DateFinished           : 15.04.2018 11:20:35
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/15/2018 9:14:32 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/15/2018 9:15:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 458a44a9-214d-4d2e-80d1-400b6c81dd3b
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 20.05.2018 03:08:58
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 03:09:04
ActiveElapsedTime      : 9
DateFinished           : 20.05.2018 03:09:04
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/20/2018 2:55:10 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/20/2018 3:01:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 518916aa-e56c-41ce-b579-6657c843f844
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 17.06.2018 02:53:31
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 02:53:42
ActiveElapsedTime      : 10
DateFinished           : 17.06.2018 02:53:42
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/16/2018 11:01:05 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/16/2018 11:04:12 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 70edaa57-d9fd-4bfd-b2c2-6935ba63b167
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 15.04.2018 11:20:25
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 15.04.2018 11:20:35
ActiveElapsedTime      : 10
DateFinished           : 15.04.2018 11:20:35
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/15/2018 9:14:32 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/15/2018 9:15:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : e5fb3f6d-98c0-4453-b2ed-697263ccdd37
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 20.05.2018 03:03:51
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 03:07:58
ActiveElapsedTime      : 244
DateFinished           : 20.05.2018 03:07:58
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/20/2018 2:55:10 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/20/2018 3:01:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : a7b65a4c-a904-441f-bacf-6eb7db956122
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 17.06.2018 02:52:09
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 02:52:24
ActiveElapsedTime      : 12
DateFinished           : 17.06.2018 02:52:24
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/16/2018 11:01:05 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/16/2018 11:04:12 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : cec97a60-e6e2-4fc9-aaa6-73f63392e5a5
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 20.05.2018 03:27:01
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 03:27:08
ActiveElapsedTime      : 10
DateFinished           : 20.05.2018 03:27:08
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/20/2018 2:55:10 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/20/2018 3:01:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 840a6b1b-df89-4611-b8f0-767e3ff1a6e2
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 14.04.2018 21:10:00
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 14.04.2018 21:12:30
ActiveElapsedTime      : 148
DateFinished           : 14.04.2018 21:12:30
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/14/2018 9:10:59 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/14/2018 9:12:30 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : ad95d581-a5bc-45db-8661-8bebdc897be7
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 17.06.2018 02:55:33
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 02:55:47
ActiveElapsedTime      : 13
DateFinished           : 17.06.2018 02:55:47
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/16/2018 11:01:05 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/16/2018 11:04:12 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : ec6956bc-ba37-415a-9f0c-8d15a859901a
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 20.05.2018 22:49:48
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 22:49:30
ActiveElapsedTime      : 9
DateFinished           : 20.05.2018 22:49:30
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/20/2018 9:42:39 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/20/2018 9:45:45 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : f9c0aeb8-2c8d-47a4-b562-8d73251b6e6b
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 12.06.2018 22:25:57
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 12.06.2018 22:24:52
ActiveElapsedTime      : 9
DateFinished           : 12.06.2018 22:24:52
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/12/2018 8:40:31 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/12/2018 8:43:38 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 91d9141c-7832-4e96-b093-ad0bebca8a85
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 17.06.2018 05:24:36
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 05:37:08
ActiveElapsedTime      : 751
DateFinished           : 17.06.2018 05:37:08
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/17/2018 5:30:55 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/17/2018 5:37:08 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 32ab7e85-fe03-41b3-af54-b7740904a33f
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 17.06.2018 03:00:33
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 03:00:44
ActiveElapsedTime      : 10
DateFinished           : 17.06.2018 03:00:44
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/16/2018 11:01:05 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/16/2018 11:04:12 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 21c9940a-a40f-4e36-85f4-b84546eead54
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 06.06.2018 23:13:41
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 06.06.2018 23:13:49
ActiveElapsedTime      : 10
DateFinished           : 06.06.2018 23:13:49
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/6/2018 5:22:28 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/6/2018 5:25:35 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : fde95fe5-8d1b-4438-a0f2-bc85495872f6
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 20.05.2018 03:26:15
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 03:27:08
ActiveElapsedTime      : 55
DateFinished           : 20.05.2018 03:27:08
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/20/2018 2:55:10 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/20/2018 3:01:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 4ac0b36d-a920-4d51-91a5-c05e0016c84d
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 15.04.2018 11:19:32
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 15.04.2018 11:19:42
ActiveElapsedTime      : 10
DateFinished           : 15.04.2018 11:19:42
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/15/2018 9:14:32 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/15/2018 9:15:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : ce21e614-deb4-4b35-bb2c-c12778d7555f
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 20.05.2018 02:57:58
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 03:03:53
ActiveElapsedTime      : 358
DateFinished           : 20.05.2018 03:03:53
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : 
                         StorageId datastore-47360', Last Processed '5/19/2018 8:01:00 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] 
                         MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId datastore-47764', Last Processed '5/20/2018 2:55:10 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 7f6e1d2d-b8b0-4fbb-8612-c4d189f142e6
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 30.04.2018 10:38:24
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 30.04.2018 10:37:45
ActiveElapsedTime      : 9
DateFinished           : 30.04.2018 10:37:45
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/30/2018 5:06:05 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/30/2018 5:09:52 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : bb69ff59-a8de-4c9c-bc36-ce0017722b10
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 23.04.2018 23:01:14
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 23.04.2018 23:00:51
ActiveElapsedTime      : 10
DateFinished           : 23.04.2018 23:00:51
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/23/2018 7:25:52 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/23/2018 7:29:38 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : c89edd36-6211-432a-ba9d-d6685e332b89
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 17.06.2018 02:56:56
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 17.06.2018 02:57:06
ActiveElapsedTime      : 10
DateFinished           : 17.06.2018 02:57:06
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '6/16/2018 11:01:05 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '6/16/2018 11:04:12 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : bcc986f1-8dc5-4fda-a62b-d6a51b0edd65
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 20.05.2018 03:07:41
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 03:07:58
ActiveElapsedTime      : 13
DateFinished           : 20.05.2018 03:07:58
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/20/2018 2:55:10 AM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/20/2018 3:01:05 AM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : c7e0c59a-8e58-4b6f-a763-e7b7f17e461b
Active                 : False
Host                   : XA-WMS2016-01
DateStarted            : 18.03.2018 02:32:33
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 14.04.2018 21:12:30
ActiveElapsedTime      : 2396401
DateFinished           : 14.04.2018 21:12:30
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '4/14/2018 9:10:59 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '4/14/2018 9:12:02 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : 3ec11efd-ba2e-42f2-9f97-ecad61d7a55e
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 20.05.2018 01:52:06
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 20.05.2018 01:52:15
ActiveElapsedTime      : 13
DateFinished           : 20.05.2018 01:52:15
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '5/19/2018 7:57:54 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '5/19/2018 8:01:00 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion : 

TaskId                 : ef302a5a-6910-416c-bf57-fbd8606cb7b2
Active                 : False
Host                   : XA-WMS2016-02
DateStarted            : 18.03.2018 03:06:55
Metadata               : {}
CurrentOperation       : 
TaskProgress           : 100
LastUpdateTime         : 18.03.2018 03:07:05
ActiveElapsedTime      : 9
DateFinished           : 18.03.2018 03:07:05
TerminatingError       : Faulted
Type                   : DisusedImageCleanUp
Status                 : Finished
ImagesToDelete         : {HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_18] MCS-2012R2-baseDisk-datastore-47764/12 Feb 2017 19-53-35.4705Z.vmdk,resgroup-8,Vmfs : StorageId 
                         datastore-47764', Last Processed '3/17/2018 9:50:43 PM', HostingUnitUid 'f4dcd282-3d9b-478a-9107-2cafe6f6f124', Image 'DiskId Version=2,LsiLogicScsi,1000,group-v47771,[v3700_p01_14] 
                         MCS-2012R2-baseDisk-datastore-47360/MCS-2012R2-baseDisk-datastore-47360.vmdk,resgroup-8,Vmfs : StorageId datastore-47360', Last Processed '3/17/2018 9:54:30 PM'}
HeartbeatInterval      : 01:00:00
RetryInterval          : 06:00:00
WorkflowStatus         : Terminated
TaskExpectedCompletion :

Which I should process via:

Remove-ProvTask -TaskID  <EnterTaskID>

Which I didn’t want to do manually for each entry. But I remembered the session from Andreas Nick at the TecCon2018, where he showed examples about how to pipe the output of a command to a select grid. I’m not good at PowerShell at all, but I wanted to try it anyways. So after two hours of straight web research I ended up with the following code, which simplified this process a lot!

asnp citrix*
Cd XDHyp:\HostingUnits
$Hosting = Get-ChildItem | Out-GridView -PassThru -Title "Select Hosting Connection" | Select-Object -Property HostingUnitUid
Get-ProvTask | Where-Object { $_.ImagesToDelete | Where-Object { $_.HostingUnit -eq $Hosting.HostingUnitUid } } |
Out-GridView -PassThru -Title "Select Provisioning Tasks for removal" | ForEach-Object { Remove-ProvTask -TaskID $_.TaskId }

To explain each step in detail:

Line 1 Make PowerShell aware of the Citrix cmdlets.
Line 2 Switch to the Hypervisor Hosting connections of XenDesktop.
Line 3 Write the HostingUnitUid of the affected connection into a variable after a GridView Select.
Line 4 Create a list of all pending tasks and …
Line 5 Present it in a second GridView Select so you could delete all or selected tasks. The selection is being piped to the Remove command.

This will look similar to this:

In the Out-GridView you will first select the affected Hosting connection and in the second windows you will select all ProvTasks you may want to remove. Most of the time this will be all. There are certainly better ways to solve this, but the intend of this post is just to show you with how little work a repetitive task can be optimized with simple PowerShell tricks.

This worked great for me, but you should test this first!

Sometimes it can happen, that a ProvTask is “Running” and you can’t remove it. For this case I found a hint at discussions.citrix.com linked at the bottom.

Sources:

This post was previously posted on mycugc.org.

Author: Marco

Marco is an IT-System administrator and IT-Consultant with 10+ years experience. He is specialized in the delivery of virtual Apps and Desktops with Citrix solutions. In 2017 he has been awarded Citrix Technology Advocate by Citrix for his community work (#CTA). His second core area is availability & performance monitoring with Zabbix, a leading open-source solution. His employer is the German IT-Company ANAXCO, which is developing a Transport Management Software (TMS) based on Microsoft Dynamics AX. More about Marco

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.