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.
This topic is 5 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

enable psremoting

Post 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?
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: enable psremoting

Post 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.
User avatar
Elementix
Posts: 1
Last visit: Sun Jun 30, 2019 11:36 am

Re: enable psremoting

Post 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 { }
This topic is 5 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked