[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1182
  • Last Modified:

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
2 Solutions
The following article explains how to run scripts - with and without Powershell environment

MiritmAuthor Commented:
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
Shahnawaz AhmedTechnical Services SpecialistCommented:

On the PowerShell Run set-executionpolicy unrestricted
then run the script
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

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
To be more precise, you usually want to allow local scripts, but nothing downloaded from Internet sites without having a valid signature, identifying them as trustworthy. Hence, once you execute
invoke-command -ComputerName xyz { set-executionPolicy RemoteSigned }

Open in new window

you will be able to execute scripts. That can be done with the localhost too, of course.
This security setting doesn't impose a security risk; having the default of AllSigned is only for making sure you never run scripts accidentally and unkown of, to keep malicious code running in the background away.
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
Shahnawaz AhmedTechnical Services SpecialistCommented:
Thanks Qlemo...

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now