enable psremoting

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
User avatar
mqh777
Posts: 229
Joined: Tue Feb 25, 2014 1:01 pm

enable psremoting

Post by mqh777 » Thu Oct 25, 2018 7:56 am

I have .cmd file that contains the following commands.
%~dp0psexec \\machine -u acme\adminuser -p p@ssw0rd -h -d powershell.exe "enable-psremoting -force"
I can run this from a CMD window and it works on any remote Windows 7 workstation.

Within PowerShell Studio this command works.
Start-Process -Filepath "\\server\files\PsExec.exe" -ArgumentList "\\$textPC cmd.exe"
This will open up the cmd.exe on a remote machine.

Within PowerShell Studio this command does Not works.
Start-Process -Filepath "\\server\files\PsExec.exe" \\$TextPC -u acme\adminuser -p p@ssw0rd -h -d powershell.exe "enable-psremoting -force"
so I tried to copy my .cmd to the target Windows 7 machine and run that with Invoke-Command. it runs but it does not enable psremoting.

Why would this not work?

User avatar
mxtrinidad
Site Admin
Posts: 224
Joined: Sun Mar 03, 2013 12:42 pm

Re: enable psremoting

Post by mxtrinidad » Thu Oct 25, 2018 8:20 am

Please read carefully the PowerShell Get-Help information on both "Start-Process" and the "Invoke-Command".

On the Start-Process cmdlet you can't include executable parameter(s) in the "-FilePath". And, on the "Invoke-Command", you probably need to use the "-RunAsAdministrator" parameter.

Also, make sure that after executing the "Enable-Remoting" cmdlet, need to verify the Services are running. And, check that the "Startup Type" is not "Manual", or the service won't start after rebooting the system.

User avatar
Elementix
Posts: 1
Joined: Mon Sep 15, 2014 9:56 pm

Re: enable psremoting

Post by Elementix » Wed Nov 07, 2018 7:38 pm

This is what I use. Load the functions, set your $RemoteComputer variable, then run the script....or put it in a loop...whatever you want to do.

Works for me!

https://jasonspowershellblog.wordpress.com/2013/06/02/enable-psremoting-remotely/

https://github.com/JasonMorgan/Technet_Uploads/blob/master/Remote_PSRemoting/PSRemoting.ps1

Code: Select all

$WSManStatus = [bool](Test-WSMan -ComputerName $RemoteComputer -ErrorAction SilentlyContinue)
		
		if ($WSManStatus -eq $false)
		{			
			Set-WINRMListener -ComputerName $RemoteComputer
			Set-WinRMFirewallRule -ComputerName $RemoteComputer
			Set-WinRMStartup -ComputerName $RemoteComputer
			Restart-WinRM -ComputerName $RemoteComputer
		else { }

Post Reply