Converting from bytes into gigabytes

2020-02-02 01:52发布

I am using following script to get disk space audit in our enterprise environment.

Everything works fine except that I don't know how to get those values presented in GB/MB.

Any idea?

$Computers = Get-Content -Path D:\DISKSPACE_audit\Servers.txt 
Get-WmiObject Win32_LogicalDisk -ComputerName $Computers | Where-Object {
  $_.DriveType -eq 3
} | Select-Object SystemName,DeviceID,FreeSpace,Size

标签: powershell
1条回答
家丑人穷心不美
2楼-- · 2020-02-02 02:45

Divide the value by 1GB (or 1MB):

$Computers = Get-Content "D:\DISKSPACE_audit\Servers.txt"
Get-WmiObject Win32_LogicalDisk -Computer $Computers -Filter 'DriveType = 3' |
    Select-Object SystemName, DeviceID,
        @{n='FreeSpace';e={[int]($_.FreeSpace/1GB)}},
        @{n='Size';e={[int]($_.Size/1GB)}}
查看更多
登录 后发表回答