我正在运行以下powershell命令:
$cmd = Get-WmiObject -ComputerName Drex -Class Win32_volume | Where {($_.DriveLetter) -and ($_.FreeSpace)}| ft -auto DriveLetter,FreeSpace
$cmd
结果是
DriveLetter FreeSpace
----------- ---------
D: 39295995904
C: 297391972352
我需要一个包含计算机名称的附加列 我怎么能这样做?
答案 0 :(得分:1)
您可以使用calculated property:
$ComputerName = 'Drex'
$Disks = Get-WmiObject -ComputerName $ComputerName -Class Win32_volume | Where {($_.DriveLetter) -and ($_.FreeSpace)}
$Disks | Select-Object DriveLetter,FreeSpace,@{Label="Computername";Expression={$ComputerName}}
此外,ft
(Format-Table
的别名)提供了格式化字符串 - 您希望避免将格式化输出存储在变量中 - 等到您想要在管道格式化cmdlet之前显示数据< / p>
答案 1 :(得分:0)
尝试
$cmd = Get-WmiObject -ComputerName Drex -Class Win32_volume | Where {($_.DriveLetter) -and ($_.FreeSpace)}| ft -auto DriveLetter,FreeSpace, __SERVER
PSComputerName
也可以代替__SERVER