Delete multiple XenServer orphan SR’s

When a Citrix XenServer, member of a Resource Pool, is reinstalled the local storage repositories (Local storage, DVD drive) are left in the resource pool as orphans. In XenCenter, below a Resource Pool, these SR’s are marked with a red bullet.

When there are a few of these orphaned SR, you can remove these with the console command:

Note uuid of the SR’s with:

To delete this SR:

But what to do if there are to much of the orphaned SR’s ? The procedure above is very time-consuming.

Lets see if Powershell can help solve this problem. For XenServer, as for other Citrix products, are Powershell cmd-lets available. With the help from this Pdf I found the cmd-let to get the SR list.

The command let to get a list of all the SR’s is:

I had to find out which property of the SR’s is one of the orphaned SR’s… It appears that an orphaned SR has no PBD’s assigned. Because this property is returned as an array I need a way to determine a way to check this. When an array is empty teh array count is “0”.

Now we have al the UUID os the orpahned SR’s. To delete a SR in Powershell:

Combined in a script, with all the logic and cmd-lets check, will result in: