官术网_书友最值得收藏!

Running PowerShell remotely

One of the advantages of PowerShell is accessing the remote servers. Running commands on remote servers is called PowerShell remoting, and this is not something new. Many IT admins run PowerShell on their client-side desktops and access servers located in different data centers to ease the administrative effort. In the cmdlets, there is a ComputerName parameter that you can use to run the command on the remote server. You just need to ensure that the ComputerName parameter specified is seen on the network and has a remoting option enabled. Let's say you want to run the Get-Service cmdlet on the server called apps1, then you can run this:

 PS C:\>Get-Service -ComputerName apps1

So, all the cmdlets that you run locally can be run on the remote server just by specifying the ComputerName parameter with it.

PowerShell is locked down by default. In order to enable remoting, you have to run the Enable-PsRemoting cmdlet:

PS C:\> Enable-PsRemoting -Force

This command starts the Windows Remote Management (WinRM) service, sets it to start automatically with your system, and creates a firewall rule that allows incoming connections. The Force part of the command tells PowerShell to perform these actions without prompting you for each step. You should restart the WinRM service so that new settings can take effect:

PS C:\Restart-Service WinRM

For testing the connection, you can use this:

PS C:\Test-WsMan <RemoteComputer>
PS C:\Enter-PsSession -ComputerName <RemoteComputer>

Or you can run any other cmdlet with ComputerName parameter.

Please note that when you deal with servers in multiple domains or the servers in WorkGroup, there could be some challenges establishing the connectivity with remote servers, as they are sometimes tricky to work with. It is always good to work with your system administrator in case you end up with issues regarding PowerShell remoting.
主站蜘蛛池模板: 南乐县| 麻阳| 锦州市| 富平县| 石家庄市| 莒南县| 廊坊市| 渭源县| 甘谷县| 仪陇县| 剑阁县| 南投县| 柏乡县| 彭州市| 托克托县| 元谋县| 临汾市| 阿巴嘎旗| 米脂县| 嵊州市| 塔城市| 沅江市| 东丽区| 南平市| 化德县| 航空| 南宫市| 九江县| 华安县| 肥西县| 鸡泽县| 玉树县| 宜章县| 旌德县| 伊通| 德兴市| 锡林浩特市| 万源市| 乌兰县| 花莲市| 双流县|