我正在为磁盘构建报告,但需要帮助,请。这是代码:
$outputs = @()
$disks = get-wmiobject -class "Win32_LogicalDisk" -Filter 'driveType=3' -namespace "root\CIMV2"
foreach ( $disk in $disks ) {
$output = New-Object PSObject -Property @{
deviceID = $disk.caption
FileSystem = $disk.fileSystem
FreeSpace = $disk.freeSpace/1GB
Size = $disk.size/1GB
VolumeName = $disk.volumeName
used = "{0:N1}" -f ((("{0:N1}" -f ($disk.size/1gb)).ToString().replace(",",".") - ("{0:N1}" -f ($disk.freespace/1gb)).ToString().replace(",",".")) / ("{0:N1}" -f ($disk.size/1gb)).ToString().replace(",",".") * 100)
used2 = $used
}
$outputs += $output
}
$outputs | select deviceID, VolumeName, size, used, used2 | Format-Table
一切都很好,但变量 used2 中没有
deviceID VolumeName Size used used2
-------- ---------- ---- ---- -----
C: win 49,1992149353027 87,4
D: data 170,701168060303 70,7