1.远程机器首先得开启允许PowerShell远程访问
Enable-PSRemoting -Force -SkipNetworkProfileCheck
2. 本地计算机在远程机器上执行命令,并返回结果
$result = Invoke-Command -ScriptBlock { Get-HotFix |select -First 5 } -ComputerName localhost,127.0.0.1
#给远程机器结果分组
$groups = $result | Group-Object -Property PSComputerName -AsHashTable
foreach($computer in $groups.Keys)
{
$singleResult = $groups.$computer
#单个远程机器的结果
#$singleResult
#TODO:用你自己本地的Excel代码处理一下
#保存的文件名可以 使用
"D:\$computer.report.xls"
}
