准备步骤:

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
 winrm.cmd

 

相关文章:

  • 2021-08-05
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2022-02-16
  • 2021-11-21
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-12-26
  • 2021-11-28
相关资源
相似解决方案