• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1219
  • 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
0
Miritm
Asked:
Miritm
2 Solutions
 
regmigrantCommented:
The following article explains how to run scripts - with and without Powershell environment

http://technet.microsoft.com/en-us/library/ee176949.aspx
0
 
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
0
 
Shahnawaz AhmedTechnical Services SpecialistCommented:
Dear,

On the PowerShell Run set-executionpolicy unrestricted
then run the script
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
regmigrantCommented:
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
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
regmigrantCommented:
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
0
 
Shahnawaz AhmedTechnical Services SpecialistCommented:
Thanks Qlemo...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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