【发布时间】:2017-01-04 08:47:18
【问题描述】:
我有一个脚本,它可以创建多个作业并在作业中存储两个简单的值。
Start-Job -ScriptBlock {param ([string]$compip) tnc $compip | select RemoteAddress,PingSucceeded -WarningAction SilentlyContinue} -ArgumentList $compip
这很好用。我想知道的是如何将以下代码存储到变量中?
Get-Job | Receive-Job | sort RemoteAddress | FT
我已经尝试过了,但它并没有像我想象的那样工作:
$pcs = Get-Job | Receive-Job | sort RemoteAddress | FT
$pcs.RemoteAddress
我是不是走错了路?我想存储来自上面get-job 命令的数据,以便稍后在脚本中使用这些值。我认为它会起作用,因为输出看起来正确:
命令:
Get-Job | Receive-Job | sort RemoteAddress | FT
输出:
RemoteAddress PingSucceeded
------------- -------------
192.168.0.163 True
192.168.0.101 False
192.168.0.2 False
192.168.0.251 True
【问题讨论】:
-
简单删除
FT。格式表不用于存储数据。只是在控制台上查看。格式 cmdlet 会破坏对象,因此您不能再以预期的方式使用它们。我将为此做一个更长的答案以供将来参考。
标签: powershell