help with trying to enable-psremoting with a script

by willbs at 2013-03-15 11:01:35

when i try to enable-psremoting with a command

psexec \server -u username -p password cmd /c 'echo . | powershell.exe -command "enable-psremoting -force" '

it works fine

when i try to enable-psremoting with a script, with the command in it, it won’t work

psexec \server -u username -p password cmd /c 'echo . | powershell.exe -file "D:\serverfolders\documents\testproc.ps1" '

any ideas?
by DonJ at 2013-03-15 11:23:26
Assuming the script contains enable-psremoting -force, I’d ask what the execution policy is on the remote computer. Doing this with PSExec is tough because you’re not going to see any error messages that might be returned by the shell.
by willbs at 2013-03-15 11:41:00
the execution policy on the remote computer is restricted
by DonJ at 2013-03-15 11:51:17
Then scripts can’t run. Specify -ExecutionPolicy RemoteSigned on your command line.
by willbs at 2013-03-15 12:17:50
worked like a charm!!!

i disabled psremoting, tried to do a remote command, wouldn’t work, then i ran

psexec \server -u username -p password cmd /c 'echo . | powershell.exe -command "set-executionpolicy -executionPolicy RemoteSigned -force" '

psexec \server -u username -p password cmd /c 'echo . | powershell.exe -file "D:\serverfolders\documents\testproc.ps1" ’

script disables psremoting

tried to do a remote command, worked fine

thanks again oh guru dude