PowerShell says “execution of scripts is disabled on this system.”

前端 未结 30 2218
傲寒
傲寒 2020-11-22 00:45

I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error:

Management_Instal

相关标签:
30条回答
  • 2020-11-22 01:28

    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.

    0 讨论(0)
  • 2020-11-22 01:31

    In the PowerShell ISE editor I found running the following line first allowed scripts.

    Set-ExecutionPolicy RemoteSigned -Scope Process
    
    0 讨论(0)
  • 2020-11-22 01:31

    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}
    
    0 讨论(0)
  • 2020-11-22 01:32

    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?

    0 讨论(0)
  • 2020-11-22 01:33

    Open cmd instead of powershell. This helped for me...

    0 讨论(0)
  • 2020-11-22 01:36

    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

    0 讨论(0)
提交回复
热议问题