准备步骤:
1、在远程机器上执行winrm quickconfig -q,具体作用请看执行结果。
2、在本地机器上执行set-item wsman:localhost\client\trustedhosts -value *,具体作用是将所有计算机添加到受信任主机列表。
然后就可以远程执行脚本了,示例:
$secPasswd = ConvertTo-SecureString "1qaz@WSX" -AsPlainText –Force $curUser = New-object -typename System.Management.Automation.PSCredential("\Administrator",$secPasswd) $vmame = "10.252.38.84" $cmdstr=New-PSSession -ComputerName $vmame -Credential $curUser invoke-command -session $cmdstr -scriptblock {echo "hello";}
关联资料:
get-help about_Remote_Troubleshooting
get-help about_Remote_Requirements
get-help about_Remote_FAQ
get-help about_Remote_FAQ
get-help about_remote
winrm.cmd