我正在通过 Get-WmiObject 获取一些信息:
$logicalDisks = Get-WmiObject -ComputerName $cmpSys Win32_LogicalDisk
然后创建一些非常基本的 HTML 代码来逐个驱动地显示它:
Foreach ($disk in $logicalDisks) {
If ($disk.DriveType -eq 3) {
$disksize = [math]::round(($disk.size / 1048576))
$freespace = [math]::round(($disk.FreeSpace / 1048576))
$percFreespace=[math]::round(((($disk.FreeSpace / 1048576)/($disk.Size / 1048676)) * 100),0)
$body += @"
<font color="red">Drive Letter: </font>$($disk.DeviceID)
<br>
<font color="red">Volume Label: </font>$($disk.VolumeName)
<br>
<font color="red">FileSystem Type: </font>$($disk.FileSystem)
<br>
<font color="red">Disk Size (MB): </font>$($disksize)MB
<br>
<font color="red">Free Space (MB) / %: </font>$($freespace)MB / $($percFreeSpace)%
<br>
<br>
"@
}
}
然而,这个显示是相当通用的,我想要一份有用的报告传递给其他部门。我怎么能在表格中格式化它?就像是:
DriveLetter VolumeLabel FileSystemType DiskSize Freespace %
C OS NTFS 100GB 32%
E DATA NTFS 1000GB 2%