I am trying to run a cmd
file that calls a PowerShell script from cmd.exe
, but I am getting this error:
Management_Instal
I had a similar issue and noted that the default cmd
on Windows Server 2012, was running the x64 one.
For Windows 7, Windows 8, Windows 10, Windows Server 2008 R2 or Windows Server 2012, run the following commands as Administrator:
x86 (32 bit)
Open C:\Windows\SysWOW64\cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned
x64 (64 bit)
Open C:\Windows\system32\cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned
You can check mode using
echo %PROCESSOR_ARCHITECTURE%
[Environment]::Is64BitProcess
References:
MSDN - Windows PowerShell execution policies
Windows - 32bit vs 64bit directory explanation
Most of the existing answers explain the How, but very few explain the Why. And before you go around executing code from strangers on the Internet, especially code that disables security measures, you should understand exactly what you're doing. So here's a little more detail on this problem.
From the TechNet About Execution Policies Page:
Windows PowerShell execution policies let you determine the conditions under which Windows PowerShell loads configuration files and runs scripts.
The benefits of which, as enumerated by PowerShell Basics - Execution Policy and Code Signing, are:
- Control of Execution - Control the level of trust for executing scripts.
- Command Highjack - Prevent injection of commands in my path.
- Identity - Is the script created and signed by a developer I trust and/or a signed with a certificate from a Certificate Authority I trust.
- Integrity - Scripts cannot be modified by malware or malicious user.
To check your current execution policy, you can run Get-ExecutionPolicy. But you're probably here because you want to change it.
To do so you'll run the Set-ExecutionPolicy cmdlet.
You'll have two major decisions to make when updating the execution policy.
Restricted
† - No Script either local, remote or downloaded can be executed on the system.AllSigned
- All script that are ran require to be digitally signed.RemoteSigned
- All remote scripts (UNC) or downloaded need to be signed.Unrestricted
- No signature for any type of script is required.LocalMachine
† - The execution policy affects all users of the computer.CurrentUser
- The execution policy affects only the current user.Process
- The execution policy affects only the current Windows PowerShell process.† = Default
For example: if you wanted to change the policy to RemoteSigned for just the CurrentUser, you'd run the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Note: In order to change the Execution policy, you must be running PowerShell As Adminstrator. If you are in regular mode and try to change the execution policy, you'll get the following error:
Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy for the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option.
If you want to tighten up the internal restrictions on your own scripts that have not been downloaded from the Internet (or at least don't contain the UNC metadata), you can force the policy to only run signed sripts. To sign your own scripts, you can follow the instructions on Scott Hanselman's article on Signing PowerShell Scripts.
Note: Most people are likely to get this error whenever they open Powershell because the first thing PS tries to do when it launches is execute your user profile script that sets up your environment however you like it.
The file is typically located in:
%UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
You can find the exact location by running the powershell variable
$profile
If there's nothing that you care about in the profile, and don't want to fuss with your security settings, you can just delete it and powershell won't find anything that it cannot execute.
If you are in an environment where you are not an administrator, you can set the Execution Policy just for you, and it will not require administrator.
Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"
or
Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "Unrestricted"
You can read all about it in the help entry.
Help Get-ExecutionPolicy -Full
Help Set-ExecutionPolicy -Full
I have also faced similar issue try this hope it helps someone As I'm using windows so followed the steps as given below Open command prompt as an administrator and then go to this path
C:\Users\%username%\AppData\Roaming\npm\
Look for the file ng.ps1 in this folder (dir) and then delete it (del ng.ps1)
You can also clear npm cache after this though it should work without this step as well. Hope it helps as it worked for me.
Hope it helps
If you're using Windows Server 2008 R2 then there is an x64 and x86 version of PowerShell both of which have to have their execution policies set. Did you set the execution policy on both hosts?
As an Administrator, you can set the execution policy by typing this into your PowerShell window:
Set-ExecutionPolicy RemoteSigned
For more information, see Using the Set-ExecutionPolicy Cmdlet.
When you are done, you can set the policy back to its default value with:
Set-ExecutionPolicy Restricted
RemoteSigned: all scripts you created yourself will be run, and all scripts downloaded from the Internet will need to be signed by a trusted publisher.
OK, change the policy by simply typing:
Set-ExecutionPolicy RemoteSigned