Solved

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

Posted on 2014-02-11
8
947 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 8

Expert Comment

by:Shahnawaz Ahmed
ID: 39850311
Dear,

On the PowerShell Run set-executionpolicy unrestricted
then run the script
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 69

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 8

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

820 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