0

I have tried get-volume, wmi/cim etc, but every example I've tried lists all volumes. What I need is a list of only the local volumes, not any cluster volumes.

Solved - code below: $myDisks = Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object –FilterScript {$.DriveType -Eq 3} | Select-Object DeviceID, VolumeName, Size, FreeSpace, @{Name="UsedSpace"; Expression={$.Size - $_.FreeSpace}} | Sort-Object -Property DeviceID $myServer = (Get-Content env:COMPUTERNAME).ToUpper() Import-Module FailoverClusters $myCluster = $(Get-Cluster).Name $myClusterDisks = Get-CimInstance -Namespace Root\MSCluster -ClassName MSCluster_Resource -ComputerName $myCluster | Where-Object –FilterScript {($.Type -eq 'Physical Disk') -and ($.OwnerNode -eq $myServer)} $myClusterVolumes = $myClusterDisks | %{Get-CimAssociatedInstance -InputObject $_ -ResultClassName MSCluster_DiskPartition} | Select-Object Path, VolumeLabel, TotalSize, FreeSpace, @{Name="UsedSpace"; Expression={$.TotalSize - $.FreeSpace}} | Sort-Object Path $myLocalVolumes = $myDisks | Where {$_.DeviceId -notin @($myClusterVolumes.Path)}

5
  • Welcome to SO. Can you exclude cluster shared volume file systems (CSVFS)? For example, Get-Volume | where {$_.FileSystem -ne 'CSVFS'} | ft or perhaps Get-Volume | where {$_.FileSystem -in @('NTFS','FAT32','ReFS')} | ft Commented Jun 7, 2020 at 16:22
  • Hmmm, not sure what "CSVFS" is, all the cluster vols are NTFS or ReFS. Commented Jun 8, 2020 at 17:24
  • Lee, you put me on the right track with your "where -in" clause. I basically had to get all disks, then get only cluster disks, then pull all disks that were -notin the cluster disks. Not as straight-forward as I would have hoped from Powershell, but it gets the job done. Thanks. Commented Jun 8, 2020 at 20:29
  • Please see Can I answer my own question? where it talks about how self-answering a question is not only allowed but encouraged. Note that regardless of who happens to post that problem-solving answer, the proper way to indicate it is the solution is to accept the answer and never to edit it into the question. See also Markdown help and How do I format my code blocks? for how to post readable code blocks. Commented Jun 8, 2020 at 21:06
  • Thanks for the links, I'll read up. Commented Jun 10, 2020 at 13:55

1 Answer 1

0

In some cases, local disks have a Disk Number, non-local ones do not. Therefore, to get the volumes for only the disks which exist on the local cluster, exclude the disks where the DiskNumber returned by Get-Partitions is null. In other cases, the 'AccessPaths' for the cluster volumes are null, so you can exclude the partitions with a filter on that. Then you can get the volumes matching those partitions.

$parts = Get-Partition | Where-Object -Property 'DiskNumber' -ne $null
$parts | Format-Table -AutoSize -Property 'OperationalStatus', 'Type', 'DiskNumber', 'DriveLetter', 'IsActive', 'IsBoot', 'IsHidden', 'IsOffline', 'IsShadowCopy', 'IsSystem', 'MbrType', 'NoDefaultDriveLetter', 'Offset', 'PartitionNumber', 'Size', 'TransistionState', 'AccessPaths'
$vols = Get-Volume -Path ( $parts.AccessPaths -match '^\\\\\?\\Volume{' )
$vols | Format-Table -AutoSize -Property 'OperationalStatus', 'HealthStatus', 'DriveType', 'FileSystemType', 'FileSystemLabel', 'AllocationUnitSize', 'DriveLetter', 'Size', 'SizeRemaining'

To return only volumes with drive letters, add this to the end of the first line above:

 | Where-Object -Property 'DriveLetter' -ne 0x00
Sign up to request clarification or add additional context in comments.

2 Comments

Rob, running your code gives me an array of all local, cluster & mounted volumes with no way to differentiate between them. I'm looking for a way to return an array of either just the local vols or just the cluster vols, and always exclude any mounted vols. Thanks, -steve
SSchaub, For me, the AccessPaths from the second line of that code are all blank for the cluster volumes, so the third line successfully filters out the cluster volumes. What do you see for those AccessPaths?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.