使用Powershell 远程执行

使用Powershell 远程执行

1、确认winrm 启动状态 get-service winrm
在services.msc中将Windows Remote Management设置为开机启动
配置Powershell 远程执行:Enable-PSRemoting –force

2、设置远程信任主机:(双方主机都要设置,若是Windows Server 则需要域认证账户)
winrm s winrm/config/client ‘@{TrustedHosts=”RemoteComputer”}’
On both computers, configure the TrustedHosts setting so the computers will trust each other. For example, if you’re doing this on a trusted home network, you can use this command to allow any computer to connect:Set-Item wsman:\localhost\client\trustedhosts *

3、确定remote host 在运行,且可以接收请求:winrm quickconfig
测试连接 Test-WsMan COMPUTER
4、执行远程命令块:Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME
5、打开远程Powershell窗口:Enter-PSSession -ComputerName COMPUTER -Credential USER

参考链接:
http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/
https://technet.microsoft.com/en-us/magazine/ff700227.aspx
http://www.pstips.net/auto-login-and-invoke-remoting-command.html

你可能感兴趣的:(计算机网络)