• Contact Us
  • About Us
  • Privacy Policy

TrustGuide

Guides and hows, tips for everyone

  • Home
  • Windows
  • Android
  • IT
    • Programming language
  • FaceBook
  • iPhone
  • Chrome
  • Photoshop

Run Powershell Script On Remote Computer – A Complete Guide

September 28, 2022 by davidmr Leave a Comment

If you want to undertake commands for just sole or numerous remote computers, you can utilize the Powershell Remoting to perform this process. 

To learn more about this computer feature, you can access the WS Web Management services, where the Powershell Remoting is based. Thanks to this wonderful feature, you can easily reach the remote computer and interact with the session mode.

Outlined below are some measures and tips for you to run Powershell Script on remote computer. If you find them useful, follow our Trustguide team for more essential information. 

How To Configure The WinRM Via Powershell Remoting

If you want to run Powershell Script on remote computer, you must activate the WinRM and have it operated on the software computer device in case it is switched off by default.

The reason is that HTTP or HTTPS networking addresses are responsible for communication and connection between two mobile devices in most situations. Therefore, all the networking traffic on the Internet base is likely to be encrypted.

After finding out the reason why WinRM is compulsory to set up, you can check its status by undertaking this command of Get-service: 

get-service winrm

https://theitbros.com/wp-content/uploads/2020/10/word-image-21.png

Now, the WinRM is operating. Should it run improperly or experience a sudden shutdown state, you can use the following command, which will help the computer to adjust and switch to the Automatic startup state and consequently protect Windows Firewall: 

Enable-PSRemoting

You can also use Powershell to activate the Windows Defender or navigate to the GUI to perform: 

Set-NetFirewallRule -Name “WINRM-HTTP-In-TCP” -RemoteAddress Any

Set-NetFirewallRule -Name “WINRM-HTTP-In-TCP-NoScope” -RemoteAddress Any

https://theitbros.com/wp-content/uploads/2020/10/word-image-22.png

Under a few circumstances, a remote device does not connect to the main AD forest. In other words, it does not belong to a workgroup. You can make an addition of a Public networking driver with a view to allowing the WinRM traffic to enter through the Windows Defender Firewall: 

Set-NetFirewallRule -Name “WINRM-HTTP-In-TCP-PUBLIC” -RemoteAddress Any

To examine the remote server connect through the WinRM, you can follow the command: 

Test-WSMan server1

https://theitbros.com/wp-content/uploads/2020/10/word-image-23.png

You are successful in running the Powershell Script on your remote computer if you reap a response. Good luck!

Run The Remote Command Through Powershell

If you want to use the Powershell as a connection bridge between the Powershell remoting and the remote driver, follow this command: 

Enter-PSSession Server1

The result is that the CLI screen will undergo some changes, and you can connect the remote computer with the assistance of WinRM now. Afterward, all interactive commands’ sessions previously stored in Powershell are displayed on the computer. 

To put an end to them, you can follow the command below: 

Exit-PSSession

https://theitbros.com/wp-content/uploads/2020/10/word-image-24.png

Utilize The Invoke-command In Order To Perform Powershell Script

If you desire to run a load of commands belonging to the ScriptBlock section and remotely connect Powershell to the computer Server1, you can consider this command as follows: 

Invoke-Command -ScriptBlock {Restart-Service spooler} -ComputerName server1

Or separate the following command with the assistance of semicolons to execute or display codes on the Powershell system:

Invoke-Command -ScriptBlock {Restart-Service spooler;Get-Date; wmic qfe list} -ComputerName server1

When you want to perform a process with the help of Invoke-command, the outcome of the PoSh won’t turn back. To grasp more necessary information about the background, turn to this Receive-Job cmdlet: 

https://theitbros.com/wp-content/uploads/2020/10/word-image-25.png 

Another great function of Powershell is that you are able to execute PS1 scripts. To undertake this task, you must rely on the -FilePath folder in lieu of -ScriptBlock. Below is an instance for you:

Invoke-Command -FilePath c:\ps\tune.ps1 -ComputerName server1,server2,server3

https://theitbros.com/wp-content/uploads/2020/10/word-image-26.png

The Bottom Line

As you can see, the Powershell offers ample opportunities for you to run scripts and commands on the remote computer. Hopefully, you can utilize this wonderful Windows software feature to a great extent.

Besides, after reading our post, we also hope that you can feel more confident to run Powershell script on remote computer. It may seem relatively challenging at first if you are a first-time user, but don’t panic and give up. You can nail it!Thank you for trusting our Trustguide site, and if you want us to post more helpful articles like this one, follow and interact with our website more positively. Wish you all the best!

Filed Under: Guideline

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Office 365 Active Directory Sync: Instructions Revealed!
  • How Does Powershell Delete Ad User? The Truth Revealed! 
  • How To Disable MFA Office 365? Easy Tips and Tricks! 
  • How To Setup Ldapsearch Windows Using AD LDS- Solved!
  • Exchange 550 5 7 1 Resolver RST Authrequired Authentication Required- Solved!

Copyright © 2023 · TrustGuide.net · Log in