Find All Disconnected Volumes

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
    $hash.Add($z, $Vol)
    $z++
}

foreach($j in $AllVolumes) {
   if(!$hash.ContainsValue($j.name)){
        $DisconnectedVolumes += $j.name
    }
    else {
        $hash.Remove($j.name)
    }
}
Write-Host "==================================================="
Write-Host "Disconnected Volumes ($($DisconnectedVolumes.Count) of $($hash.Count))"
Write-Host "==================================================="
$DisconnectedVolumes

Output examples:

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

The below results are from Get-PfaVolumes, Get-PfaHosts and Get-PfaHostVolumeConnections results to compare. All of the bold/underline highlights are the volumes that are disconnected.

PS C:\> Get-PfaHosts -Array $FlashArray
iqn wwn                                  name            hgroup             
--- ---                                  ----            ------             
{}  {21000024FF481616, 21000024FF481617} csg-ws2012r2-01 Barkz-SJ-SCVMM     
{}  {21000024FF43DBD6, 21000024FF43DBD7} csg-ws2012r2-02 Barkz-SJ-SCVMM     
{}  {21000024FF327E24, 21000024FF327E25} csg-vmw-01      Barkz-SJ-vCenter   
{}  {21000024FF48BED0, 21000024FF48BED1} csg-vmw-02      Barkz-SJ-vCenter   
{}  {21000024FF4816B8, 21000024FF4816B9} cody-esxi-05    Cody-Infrastructure
{}  {21000024FF2666D0, 21000024FF2666D1} cody-esxi-01    Cody-SF-vCenter    
{}  {21000024FF48BE9C, 21000024FF48BE9D} cody-esxi-02    Cody-SF-vCenter    
{}  {21000024FF48171A, 21000024FF48171B} cody-esxi-06    Cody-Infrastructure
{}  {21000024FF50AC6A, 21000024FF50AC6B} cody-esxi-03    Cody-SF-vCenter    
{}  {21000024FF50AC8E, 21000024FF50AC8F} cody-esxi-04    Cody-SF-vCenter    
{}  {21000024FF382406, 21000024FF382407} cody-esxi-08    Cody-NY-vCenter    
{}  {21000024FF37DBD2, 21000024FF37DBD3} cody-esxi-09    Cody-NY-vCenter
PS C:\> Get-PfaVolumes -Array $FlashArray | select name
name                    
----                    
Barkz-Datastore-1       
Barkz-NFS               
TPCE-FlatFiles-Dataset  
Barkz-Datastore-2       
Commvault-11-Library    
VSS-TEST-Volume1        
VSS-TEST-Volume2        
SQL-UsrData             
SQL-TempDb              
SQL-SysData             
WSFC-HyperV-CSV         
WSFC-Qurom              
SCVMMLibrary            
Barkz-Ex13-Db-01        
Barkz-Ex13-Db-02        
BAR                     
Mailbox-SMBR-MANUAL-01  
Mailbox-SMBR-MANUAL-21  
Barkz-ZEROTEST-Datastore
NPIV-Test-Data          
NPIV-Test-Log           
RPTTST-Data01           
RPTTST-Data02           
RPTTST-Data03           
RPTTST-Data04           
RPTTST-Data05           
RPTTST-Data06           
RPTTST-Data07           
RPTTST-Data08           
RPTTST-Data09           
RPTTST-Data10           
RPTTST-Log01            
RPTTST-Log02            
RPTTST-Log03            
RPTTST-Log04            
RPTTST-Log05            
RPTTST-Log06            
RPTTST-Log07            
RPTTST-Log08            
RPTTST-Log09            
RPTTST-Log10 

PS C:\> $ConnectedVolumes (Note: Uses Get-PfaHostVolumeConnections)
vol                   
---                   
SQL-SysData           
SQL-TempDb            
SQL-UsrData           
SCVMMLibrary          
NPIV-Test-Data        
NPIV-Test-Log         
RPTTST-Data01         
RPTTST-Data02         
RPTTST-Data03         
RPTTST-Data04         
RPTTST-Data05         
RPTTST-Data06         
RPTTST-Data07         
RPTTST-Data08         
RPTTST-Data09         
RPTTST-Data10         
RPTTST-Log01          
RPTTST-Log02          
RPTTST-Log04          
RPTTST-Log05          
RPTTST-Log06          
RPTTST-Log07          
RPTTST-Log08          
RPTTST-Log09          
RPTTST-Log10          
Barkz-Datastore-1     
Barkz-NFS             
Barkz-Datastore-2     
Commvault-11-Library  
VSS-TEST-Volume1      
VSS-TEST-Volume2      
Barkz-Ex13-Db-01      
Mailbox-SMBR-MANUAL-01
Mailbox-SMBR-MANUAL-21
Barkz-Datastore-1     
Barkz-NFS             
Commvault-11-Library  
VSS-TEST-Volume1      
VSS-TEST-Volume2      
Barkz-Ex13-Db-01      
Mailbox-SMBR-MANUAL-01
Mailbox-SMBR-MANUAL-21

Download the script from https://github.com/barkz/PurePowerShellGuy.

Cheers,
Barkz