我想在远程计算机上运行 [System.Net.Dns]::GetHostAddresses("mail") 并写入它。
Foreach($PCName in $PCNameArray) {
$arrayJobs += Invoke-Command -Credential $cred -scriptblock {
param (
[String]$ip )
$IPs = [System.Net.Dns]::GetHostAddresses("mail")
$ip = $ips[0]
} -ComputerName $PCName -AsJob -ArgumentList $ip
}
Wait-Job $arrayJobs
$ResultArray=[System.Collections.ArrayList]@()
foreach ($job in $arrayJobs) {
if ($job.State -eq 'Completed') {
$ResultArray += Receive-Job $job
}
Stop-Job $job
}
$ResultArray | Select PsComputerName,ip | Export-Csv $OutputFile -NoTypeInformation -Delimiter ';' -Encoding UTF8
如何从所有作业的 Invoke-Command 内部获取 $ip 值?