Solved

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

Posted on 2014-02-11
8
882 Views
Last Modified: 2014-02-16
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
Comment
Question by:Miritm
8 Comments
 
LVL 19

Assisted Solution

by:regmigrant
regmigrant earned 250 total points
ID: 39850282
The following article explains how to run scripts - with and without Powershell environment

http://technet.microsoft.com/en-us/library/ee176949.aspx
0
 

Author Comment

by:Miritm
ID: 39850303
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
 
LVL 7

Expert Comment

by:Shahnawaz Ahmed
ID: 39850311
Dear,

On the PowerShell Run set-executionpolicy unrestricted
then run the script
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Expert Comment

by:regmigrant
ID: 39850381
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
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
ID: 39850501
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
 
LVL 19

Expert Comment

by:regmigrant
ID: 39850631
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
 
LVL 7

Expert Comment

by:Shahnawaz Ahmed
ID: 39850841
Thanks Qlemo...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now