[英]Displaying computer name and free disk space in powershell
I'm running the following powershell command : 我正在运行以下powershell命令:
$cmd = Get-WmiObject -ComputerName Drex -Class Win32_volume | Where {($_.DriveLetter) -and ($_.FreeSpace)}| ft -auto DriveLetter,FreeSpace
$cmd
It gives as result 结果
DriveLetter FreeSpace
----------- ---------
D: 39295995904
C: 297391972352
I need to have an additional column that contains computer name 我需要另外一个包含计算机名称的列
How can i do that ? 我怎样才能做到这一点 ?
You can use a 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}}
Also, ft
(an alias for Format-Table
) provides a formatted string - you want to avoid storing formatted output in variables - wait until you want to display your data before you pipe to formatting cmdlets 此外,
ft
( Format-Table
的别名)提供了格式化的字符串-您要避免将格式化的输出存储在变量中-等待直到要显示数据后再通过管道格式化cmdlet
Try 尝试
$cmd = Get-WmiObject -ComputerName Drex -Class Win32_volume | Where {($_.DriveLetter) -and ($_.FreeSpace)}| ft -auto DriveLetter,FreeSpace, __SERVER
PSComputerName
also works instead of __SERVER
PSComputerName
也可以代替__SERVER
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.