I am trying to run a cmd
file that calls a PowerShell script from cmd.exe
, but I am getting this error:
Management_Instal
If you're here because of running it with Ruby or Chef and using `` system execution, execute as follows:
`powershell.exe -ExecutionPolicy Unrestricted -command [Environment]::GetFolderPath(\'mydocuments\')`
That command is for getting "MyDocuments" Folder.
-ExecutionPolicy Unrestricted
does the trick.
I hope it's helpful for someone else.
In the PowerShell ISE editor I found running the following line first allowed scripts.
Set-ExecutionPolicy RemoteSigned -Scope Process
I had the same problem today. 64-bit execution policy was unrestricted, while 32-bit was restricted.
Here's how to change just the 32-bit policy remotely:
Invoke-Command -ComputerName $servername -ConfigurationName Microsoft.PowerShell32 -scriptblock {Set-ExecutionPolicy unrestricted}
Several answers point to execution policy. However some things require "runas administrator" also. This is safest in that there is no permanent change to execution policy, and can get past administrator restriction. Use with schedtask to start a batch with:
runas.exe /savecred /user:administrator powershell -ExecutionPolicy ByPass -File script.ps1
from both Jack Edmonds above, and Peter Mortensen / Dhana of post How to run an application as "run as administrator" from the command prompt?
Open cmd instead of powershell. This helped for me...
You can also bypass this by using the following command:
PS > powershell Get-Content .\test.ps1 | Invoke-Expression
You can also read this article by Scott Sutherland that explains 15 different ways to bypass the PowerShell Set-ExecutionPolicy
if you don't have administrator privileges:
15 Ways to Bypass the PowerShell Execution Policy