我一直在研究这个脚本来捕获磁盘大小,但是我有它们以字节为单位并且它们很乱,我已经看了几种添加小数点的方法,但是我在转换时遇到了麻烦首先是GB,我还试图计算可用磁盘大小和使用的百分比。
$servers = (Get-AdComputer -Filter "name -like MY-VM-*'").Name | Sort-Object
foreach ($Server in $Servers)
{
$disks= get-wmiobject -ComputerName $Server Win32_volume | select-object pscomputername, Capacity, driveletter, freespace |`
format-table | out-file c:\temp\new3.txt -append
Foreach ($disk in $disks)
{
$driveletter = $disk.driveletter
$totalsize = $disk.capacity
$freespace = $disk.freespace
$freespace = [math]::round($freespace[$_] /9.3132257461548)
$Percent_Free = [math]::round(($freespace / $totalsize ) * 100)
}
}
希望有道理:)
答案 0 :(得分:1)
您的查询已在评论中得到解答。你可以直接这样做 -
$servers = (Get-AdComputer -Filter "name -like MY-VM-*'").Name | Sort-Object
foreach ($Server in $Servers)
{
$disks= get-wmiobject -ComputerName $Server Win32_volume | select-object pscomputername, Capacity, driveletter, freespace |`
format-table | out-file c:\temp\new3.txt -append
Foreach ($disk in $disks)
{
$driveletter = $disk.driveletter
$totalsize = $disk.capacity/1GB
$freespace = $disk.freespace/1GB
$Percent_Free = [math]::round(($freespace / $totalsize ) * 100)
}
}