Powershell HTML表格 [英] Powershell HTML Tables
本文介绍了Powershell HTML表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过Get-WmiObject获取一些信息:
I am taking some information via Get-WmiObject:
$logicalDisks = Get-WmiObject -ComputerName $cmpSys Win32_LogicalDisk
然后创建一些非常基本的HTML代码以逐个驱动器显示它:
Then creating some very basic HTML code to display it drive by drive:
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>
"@
}
}
但是,此显示是相当通用的,我希望将有用的报告传递给其他部门.如何在表格中设置格式?像这样:
However, this display is fairly generic, and I would like a usable report to pass on to other departments. How could I format it in a table? Something like:
DriveLetter VolumeLabel FileSystemType DiskSize Freespace %
C OS NTFS 100GB 32%
E DATA NTFS 1000GB 2%
推荐答案
表格"是ConvertTo-Html
cmdlet的默认输出格式:
"Table" is the default output format of the ConvertTo-Html
cmdlet:
gwmi Win32_LogicalDisk -Computer $cmpSys -Filter 'DriveType = 3' |
select @{n='DriveLetter';e={$_.DeviceID -replace ':'}},
@{n='VolumeLabel';e={$_.VolumeName}},
@{n='FileSystemType';e={$_.FileSystem}},
@{n='DiskSize';e={"{0}GB" -f [int]($_.Size/1GB)}},
@{n='Freespace %';e={"{0}%" -f [int]($_.FreeSpace/$_.Size*100)}} |
ConvertTo-Html -Head '<style>th,td {text-align:center;}</style>'
如果要在多台计算机上再次运行该主机(-Computer
可以使用一组主机名),则可能还需要包括主机名:
If you want to run this agains multiple computers (-Computer
can take an array of hostnames), you may want to include the hostname as well:
gwmi Win32_LogicalDisk -Computer $cmpSys -Filter 'DriveType = 3' |
select @{n='Hostname';e={$_.SystemName}},
@{n='DriveLetter';e={$_.DeviceID -replace ':'}},
@{n='VolumeLabel';e={$_.VolumeName}},
@{n='FileSystemType';e={$_.FileSystem}},
@{n='DiskSize';e={"{0}GB" -f [int]($_.Size/1GB)}},
@{n='Freespace %';e={"{0}%" -f [int]($_.FreeSpace/$_.Size*100)}} |
ConvertTo-Html -Head '<style>th,td {text-align:center;}</style>'
这篇关于Powershell HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文