Page 1 of 1

enable psremoting

Posted: Thu Oct 25, 2018 7:56 am
by mqh77777
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?

Re: enable psremoting

Posted: Thu Oct 25, 2018 8:20 am
by mxtrinidad
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.

Re: enable psremoting

Posted: Wed Nov 07, 2018 6:38 pm
by Elementix
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 { }