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?
enable psremoting
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.
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.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: enable psremoting
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.
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
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
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 { }