我试图弄清楚如何将一些文本(例如 MHz 或 GB)添加到 PowerShell 表中的结果中。可以foreach
循环吗?
Get-WmiObject Win32_PhysicalMmory |
Format-Table Banklabel, Manufacturer,
@{Label="Speed"; Expression={$_.ConfiguredClockSpeed}},
@{Label="Capacity"; Expression={[int64]($_.Capacity/1GB)}} -AutoSize
我有另一种接近的方法,但不能处理多个结果,因为它不会将信息添加到新行中。
$Disk = Get-WmiObject -Class Win32_LogicalDisk
$DiskSpace = [int64]($Disk.Size/1GB)
$FreeSpace = [INT64]($Disk.FreeSpace/1GB)
$UsedSpace = (($DiskSpace-$FreeSpace)/$DiskSpace).ToString("P0")
$OBJ = New-Object PSObject
$OBJ | Add-Member NoteProperty "ID" ($Disk.DeviceID)
$OBJ | Add-Member NoteProperty "Name" ($Disk.VolumeName)
$OBJ | Add-Member NoteProperty "Format" ($Disk.FileSystem)
$OBJ | Add-Member NoteProperty "Capacity" ("$DiskSpace-GB")
$OBJ | Add-Member NoteProperty "Free Space" ("$FreeSpace-GB")
$OBJ | Add-Member NoteProperty "Used" ($UsedSpace)
Write-Output $OBJ | Format-Table