Link to home
Start Free TrialLog in
Avatar of Miritm
Miritm

asked on

what's preventing me from invoking commands using powershell on my local desktop?

I'm learning how to work with PowerShell fore remote command execution.
I created a simple script - test.ps1 - that contains just "dir", and executes well from command line. However, when I try to execute it using invoke-command, it fails with the following message. Note that for this test I'm trying localhost, but it still fails with a security message.

Command and message text:

PS Desktop> invoke-command -ComputerName localhost -FilePath test.ps1
invoke-command : File C:\Users\mirit.VENOTION\Desktop\test.ps1 cannot be loaded because running scripts is disabled on
this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ invoke-command -ComputerName localhost -FilePath test.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [Invoke-Command], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.InvokeCommandCommand
SOLUTION
Avatar of regmigrant
regmigrant
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Miritm
Miritm

ASKER

I'm specifically interested in using invoke-command because my goal is to be able to execute the scripts remotely. Executing without "invoke-command" works well for me on the local computer
Dear,

On the PowerShell Run set-executionpolicy unrestricted
then run the script
V_2Shaha solution is also given in the link I posted - its worth reading the whole thing to help you understand how/why powershell works the way it does

- for example why the 'unrestricted' option is potentially dangerous and how you can allow invoke  for your own code but prevent someone else's from doing bad things to your computer
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Qlemo - - the OP clearly needs more than just the ability to execute the Invoke commend if he is learning to work with powershell and as the first para of the article describes his specific problem in detail before providing more detail about powershell as a whole I feel the link is  relevant.

However I do see that it was a 'lazy' response and I will be more explicit in future and make sure to quote specific commands where appropriate, my apologies
Thanks Qlemo...