0
votes

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)}

1
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')} | ftleeharvey1
Hmmm, not sure what "CSVFS" is, all the cluster vols are NTFS or ReFS.SSchaub
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.SSchaub
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.Lance U. Matthews
Thanks for the links, I'll read up.SSchaub

1 Answers

0
votes

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