Developer
Developer

Reputation: 767

Enable WinRM on a remote machine from a client machine

Requirement: Run PowerShell scripts on Remote Server from a Client Machine.

In order to run powershell scripts on a remote computer, we have to use

Enter-PSSession

In order to do the same, the client and the server must be able to communicate with each other through WinRM service. To achieve the same, we need to enable a firewall port (if not already open), create a new certificate and associate the same port with the thumbprint to enable communication.

I can achieve the same by creating a PS script, and run it on the server.

But if I have to do the same for 40 odd servers, then I need some kind of automation. So, here I am looking for help wherein I can enable communication between two servers, by not manually logging to each and every server but rather through PowerShell to enable WinRM for a server from client machine.

My end goal is to migrate all the existing infrastructure into Cloud and to achieve the same, the only hurdle is communication between to servers.

Note: I am able to achieve all the need by running a script into the server by manually logging into it and run the script. Post running the script, I am able to get Session of the server in my Client machine.

Upvotes: 0

Views: 6492

Answers (1)

Ross Lyons
Ross Lyons

Reputation: 171

Amended

Looks like your option will be to either use PSTools, which I think will work. Download the set and then use

psexec \\[computer name] -u [admin account name] -p [admin account password] -h -d powershell.exe "enable-psremoting -force"

Then you can remotely run your script.

OR

You could remotely deploy a scheduled task that points to your .PS1 file.

Upvotes: 1

Related Questions