List physical drive space

后端 未结 3 1013

I have around 200 servers and I need to get the disk space & logical drive space details (free space, used space & total space).

Here is my PowerShell query.

3条回答
  •  粉色の甜心
    2021-01-24 14:06

    Export-Csv assumes that all objects in your list are uniform, i.e. that they all have the same properties, just with different values. It takes the properties of the first element to determine what to export. Either make sure that all objects have the same properties, or use a different output method, for instance putting all disk information in an array per host and write that to the output file, e.g. like this:

    foreach ($machine in $servers) {
      $disks = @($machine)
      $disks += Get-WmiObject -Computer $machine -Class Win32_DiskDrive |
                ForEach-Object { [Math]::Round($_.Size/1GB) }
      $disks -join ',' | Add-Content 'C:\path\to\output.csv'
    }
    

    BTW, you don't need multiple WMI queries, since the first one already returns all disks including their sizes.

提交回复
热议问题