Unable to retrieve physical size of available stor

2019-07-22 15:22发布

问题:

I am half way down with my work and now stuck.

I am trying to fetch information about available storage devices for a cluster. I am able to fetch the list of available storage devices but unable to retrieve the physical disk, available free space, etc of these available storage.

I want like this. Is there any command to fetch physical disk name from Cluster Disk Name or directly can I get the disk details. For Shared Disk I am able to retrieve the details (Get-ClusterSharedVolume) but not for a non-shared disk. I want powershell or WMI script for doing so.

回答1:

You can get this information from WMI, but it takes a couple steps:

$resources = Get-WmiObject -namespace root\MSCluster MSCluster_Resource -filter "Type='Physical Disk'"
$resources | foreach {
    $res = $_
    $disks = $res.GetRelated("MSCluster_Disk")
    $disks | foreach {
        $_.GetRelated("MSCluster_DiskPartition") |
            select @{N="Name"; E={$res.Name}}, @{N="Status"; E={$res.State}}, Path, VolumeLabel, TotalSize, FreeSpace 
    }
} | ft

That will give you output like the following:

Name                  Status Path  VolumeLabel  TotalSize  FreeSpace
----                  ------ ----  -----------  ---------  ---------
Cluster Disk 2             2 K:    New Volume        5220       5163
SQL - FAS3070 SiteB        2 S:    MC_SQL            5597       5455
SM Test                    2 M:    SM Test           1024        992
DTC - FAS3070B             2 F:    MC_WITNESS        5346       5289
Cluster Disk Witness       2 E:    New Volume        5322       5267
Cluster Disk 1             2 G:    MC_DTC            5088       5035
Cluster Disk 3             2 T:    SQL               5119       4999

If you don't care about the resource name/status you can skip those steps and jump straight to the partition (and it'll run much quicker):

gwmi -namespace root\MSCluster MSCluster_DiskPartition | ft Path, VolumeLabel, TotalSize, FreeSpace

Edit: Note that the size is in MB and a Status of "2" means that the disk is online.



回答2:

you can use wmi like this:

Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" | Select DeviceID, FreeSpace

throw in a computername parameter if you wish to do it remotely

HTH, Matt

PS. for a more readable report you can try this:

Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" | 
  Select DeviceID, @{Name = "Free Space (%)" ; Expression= {[int] ($_.FreeSpace / $_.Size* 100)}},@{Name = "Free Space (GB)"; Expression = {[int]($_.Freespace / 1GB)}}, @{Name = "Size (GB)"; Expression = {[int]($_.Freespace / 1GB)}}