使用过 Linux 的都知道,Linux 的 shell 不但可以本地运行,也可以通过远程的方式连接。Powershell 也是如此,不但可以在本地运行,也可以通过远程的方式运行,不过它使用的协议,和 Linux 的 shell 不太一样。
Powershell 使用 WinRM 进行远程连接的,所以你想要通过 Powershell 远程连接到远程主机,必须先要在远程主机上配置 WinRM。
下面我们来看一下,怎么配置吧:
在远程主机上开启远程连接:
PS C:\Users\Administrator> Enable-PSRemoting
对于多主机的情况下,你可以通过 Windows AD 的组策略进行配置。
在本地,设置远端主机是信任的:
PS C:\Windows\system32> Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.12"
WinRM Security Configuration.
This command modifies the TrustedHosts list for the WinRM client. The computers in the TrustedHosts list might not be
authenticated. The client might send credential information to these computers. Are you sure that you want to modify
this list?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
建立远程连接:
PS C:\Windows\system32> Enter-PSSession -ComputerName 192.168.1.12 -Credential Administrator
在弹出的验证窗口中,输入密码:
(通过 Windows AD 验证,是一个比较好的选项。)
建立起连接后,你就可以像在本地一样,运行远端主机的 powershell 了:
[192.168.1.12]: PS C:\Users\Administrator\Documents>
在 powershell 中,还有一个一对多建立远程的命令 —— Invoke-Command,有兴趣的可以自己试一下,使用方式类似,只是后面计算机名是多个主机名,或 IP,之间使用逗号隔开。
<<: #2 - Button文字换起来! (CSS: 移动位置)
今日题目 题目连结:605. Can Place Flowers 题目主题:Array, Greed...
实务上,我们可能并没有自己想的那麽了解系统的真实面,这也造就一些起步上的困难,反思一下,这也关於问题...
多子元素元件包含Scaffold、AppBar、Row、Column、Stack、IndexedSt...
昨天已经找到的KKBOX用来传资料的API,也知道各个参数的意义了,今天就实际将资料抓下来吧! 歌...
Command:filter filtertype filterdata filtertype fi...