Find All Disconnected Volumes

Updates
5/2/2017 – Added size of disconnected volume output.
5/1/2017 – Fixed bugs.

There are many ways to determine what volumes are connected to a host or host group, but there is no way to easily see via the PowerShell SDK what volumes are disconnected/unused.

PowerShell:

$FlashArrayID = Read-Host -Prompt"Enter the Pure Storage FlashArray (IP/FQDN)"
$FlashArray = New-PfaArray -EndPoint $FlashArrayID -Credentials (Get-Credential) -IgnoreCertificateError

$ConnectedVolumes = @($null)
$AllVolumes = @($null)
$DisconnectedVolumes = @($null)
$z=0

$Hosts = Get-PfaHosts -Array $FlashArray
ForEach ($HostVol in $Hosts) {
    $ConnectedVolumes += @(Get-PfaHostVolumeConnections -Array $FlashArray -Name $HostVol.name | select vol)
}

$AllVolumes = @(Get-PfaVolumes -Array $FlashArray | select name)
$hash= @{}

foreach ($i in $ConnectedVolumes) {
    $Vol = $i.vol
    if(!$hash.ContainsValue($i.vol)){
        $hash.Add($z, $Vol)
    }
    $z++
}


foreach($k in $AllVolumes) {
    if(!$hash.ContainsValue($k.name)){
        $size = "$((Get-PfaVolume -Array $FlashArray -Name $k.name).size/1024/1024/1024)GB"
        $DisconnectedVolumes += "$($k.name) [$size]"
    }
    else {
        $hash.Remove($k.name)
    }
}

Write-Host "==================================================="
Write-Host "Disconnected Volumes ($($DisconnectedVolumes.Count-1) of $($hash.Count))"
Write-Host "==================================================="
$DisconnectedVolumes

Output example:

===================================================
Disconnected Volumes (7 of 42)
===================================================
TPCE-FlatFiles-Dataset
WSFC-HyperV-CSV
WSFC-Qurom
Barkz-Ex13-Db-02
BAR
Barkz-ZEROTEST-Datastore
RPTTST-Log03

Download the scriptGet-DisconnectedVolumes.ps1 from https://github.com/PureStorage-OpenConnect/powershell-scripts.

Cheers,
Barkz

5 comments
  1. Hi,

    We have only 1 disconnected volume, when we execute the above script, it shows 2 disconnected volumes. Also we have 21 volumes in our array, it shows “Disconnected volumes (2 of 193)

    Please help

    -Madhusudan

    • Hi Madhusudan –

      I have fixed the issue in the script. Thanks for posting your comment and helping to make the script better for other customers.

      The issue was related to the hash table I created was 0 based and I did not account for that with the tally. Secondly, when I retrieved the the volumes I did not account for volumes that were connected to Host Groups. So when a volume would be connected to each host of a host group it would add that into the hash table each time.

      Thanks,
      Barkz

Leave a Reply to Barkz Cancel Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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