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.
User avatar
Posts: 237
Joined: Tue Feb 25, 2014 1:01 pm

enable psremoting

Post by mqh777 »

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
Posts: 399
Joined: Sun Mar 03, 2013 12:42 pm

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
Posts: 1
Joined: Mon Sep 15, 2014 9:56 pm

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!



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 { }