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:

xe sr-list

uuid ( RO) : 9901ddd7-6c40-98cf-9ebd-ad381d651ec7
name-label ( RW): DVD drives
name-description ( RW): Physical DVD drives
host ( RO): <not in database>
type ( RO): udev
content-type ( RO): iso

Note uuid of the SR’s with:

host  (RO): <not in database>

To delete this SR:

xe sr-forget uuid=

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″.

Get-XenServer:SR | where-object {$_.PBDs.count -eq 0}

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

Invoke-XenServer:SR.Forget -SR

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

function checkForPSSnapins ()
  Write-Host "-- Verifying PowerShell snapin..."
  #Check if the snapin is installed AND registered properly.
  if(Get-PSSnapin -Name "XenServerPSSnapIn" -Registered -ErrorAction SilentlyContinue){
  #if the snapin is not loaded, load it.
    if (!(Get-PSSnapin "XenServerPSSnapIn" -ErrorAction SilentlyContinue)) {
      Write-Host "-- Loading XenServerPSSnapIn."
      Add-PSSnapin XenServerPSSnapIn
    Write-Host "-- Citrix XenServerPSSnapIn is not installed/registered on this machine."
    Write-Host "-- Download The XenServer SDK for PowerShell from: http://www.community.citrix.com/cdn/xs/sdks"
    Write-Host "-- Script will now exit."

$USERNAME = "root"
$PASSWORD = "Password"



$XS = Connect-XenServer -url http://$POOLMASTER -UserName $USERNAME -Password $PASSWORD

$objSRs = Get-XenServer:SR | Where-Object {$_.PBDs.count -eq 0} | sort-object -Property name_label

ForEach ($objSR in $objSRs)
  Write-host $objSR.name_label " " $objSR.uuid
  Invoke-XenServer:SR.Forget -SR $objSR.uuid