Why are my PowerShell scripts not running?

前端 未结 9 1096
感情败类
感情败类 2020-12-07 08:33

I wrote a simple batch file as a PowerShell script, and I am getting errors when they run.

It\'s in a scripts directory in my path. This is the error I get:

相关标签:
9条回答
  • 2020-12-07 08:50

    Use:

    Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
    

    Always use the above command to enable to executing PowerShell in the current session.

    0 讨论(0)
  • 2020-12-07 08:56

    You need to run Set-ExecutionPolicy:

    Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run.  Only individual commands may be run.
    
    Set-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.
    
    Set-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.
    
    Set-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run.  Warns before running downloaded scripts.
    
    Set-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.
    
    0 讨论(0)
  • 2020-12-07 09:00
    Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
    

    The above command worked for me even when the following error happens:

    Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
    
    0 讨论(0)
提交回复
热议问题