Powershell 3.0 : Alternative to “Get-Volume”

独自空忆成欢 提交于 2021-02-07 07:28:09

问题


I'm trying to get various properties for each hdd-volume on the computer.

I was using the cmdlet get-volume and then walking through it via foreach, but that cmdlet does not exist in Windows Server 2008. :(

Does anybody know an alternative?

I just need the drive letter, objectId/guid, free space, total space, and the name of each volume.


回答1:


The WMI class Win32_Volume has the information you are looking for

Get-WMIObject -Class Win32_Volume | Select DriveLetter,FreeSpace,Capacity,DeviceID,Label

Which a little fancy footwork you can make the drive space properties looking a little more appealing.

Get-WmiObject -Class Win32_Volume | 
        Select DriveLetter,
            @{Label="FreeSpace (In GB)";Expression={$_.Freespace/1gb}},
            @{Label="Capacity (In GB)";Expression={$_.Capacity/1gb}},
            DeviceID,Label |
        Format-Table -AutoSize



回答2:


Get-Volume is only in Powershell 4.

You can do this tho:

Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID, Size, FreeSpace, VolumeName


来源:https://stackoverflow.com/questions/26168371/powershell-3-0-alternative-to-get-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!