다음을 통해 공유


Administering Windows with PowerShell Remoting

Windows PowerShell can remotely manage a Windows computer by enabling a feature called PowerShell Remoting. This feature can be useful when there is no GUI-based tool is available.

A service called Windows Remote Management (WinRM) makes a Windows device capable of being managed remotely. You need to set the appropriate firewall rules on both sides of the network or hosts to make PowerShell remoting possible. When connected via PowerShell remoting, you can run cmdlets and scripts as if you are running those commands interactively on the local computer. However, the Windows Firewall exception for the WinRM listener will fail if any of the network cards are configured to have a public type. In this scenario, we are configuring WinRM for computers that have no public network cards (the firewall will refuse to create exceptions on public network cards). If you have any public network card, you must change the network card type to either private or domain or disable it completely.

Network Card Type To Private

To change the network card type to private, it is very straightforward, open network status by right click on the network icon from bottom right of the desktop then select Open Network & Internet settings (in this scenario, I used Windows 10)
https://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri1.png

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri1.pngFrom Network status windows, click on Change connection properties.
https://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri2.png

Select Private radio button
https://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri3.png

Use Windows PowerShell to Manage Remote Computers

Windows PowerShell remoting is disabled by default on Windows 10 operating system. You need to manually enable it to perform remoting. You can run the WinRm quickconfig command to enable Windows Remote Management service. The enable-PSremoting -force command enables Windows PowerShell remoting.

In this section, we will use various cmdlets to manage remote computers. I am using two Windows 10 machines (SPMonkey-Win10-01 and SPMonkey-Win10-02) as shown below:

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri4.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri4.png

Configuring The Workstation Machine: SPMonkey-Win10-01

Firstly, we need to update the WinRM service on the machine SPMonkey-Win10-01. From Start menu, search for 'services' or press windows key and R to run the Run command then enter "services.msc".

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri5.pnghttps://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri5.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri5.png

From Services windows, look for "Windows Remote Management (WS-Management)" then right click and select Properties to open its properties windows.

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri6.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri6.png

Change Startup type to "Automatic" and click on Start button to start the service then click OK button to close the properties windows. Close the Services window.

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri7.pnghttps://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri7.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri7.png

After the Windows Remote Management (WS-Management) has been started and running, now it's time to open Windows PowerShell by run as Administrator to run some cmdlets.

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri8.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri8.png

Note: In the User Account Control dialog box, click Yes.

At the command prompt, type winrm quickconfig command to enable WinRM and press Enter.

To confirm WinRM is enable type Enable-PSRemoting -Force command to enable PowerShell remoting and press Enter.

To configure the trusted hosts, type Set-Item wsman:\localhost\client\trustedhosts * command and press Enter.

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri9.pnghttps://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri9.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri9.png

Configuring the workstation machine SPMonkey-Win10-02

Open the Windows PowerShell by run as Administrator. At the command prompt, type winrm
quickconfig command to enable WinRM and press Enter.

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri10.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri10.png

Now we are done with both computers SPMonkey-Win10-01 and SPMonkey-Win10-02. It is time to go back to the first computer SPMonkey-Win10-01 and manage the second computer by using Windows PowerShell Remoting.

Administering Windows with PowerShell Remoting

From Windows PowerShell windows on the first computer SPMonkey-Win10-01, type Enter-PSSession -ComputerName 192.168.0.5 -Credential Administrator with 192.168.0.5 is the IP address of SPMonkey-Win10-02.

Enter the administrator password then hit OK button. You are now in remote session that means that remote connection with 192.168.0.5, which is SPMonkey-Win10-02, is established.

https://social.technet.microsoft.com/wp-content/uploads/2019/11/111019_0220_Administeri11.pnghttps://spmonkey.com/wp-content/uploads/2019/11/111019_0220_Administeri11.png

Conclusions

  

See Also