내 PowerShell 스크립트가 실행되지 않는 이유는 무엇입니까?

StackOverflow https://stackoverflow.com/questions/10635

  •  08-06-2019
  •  | 
  •  

문제

PowerShell 스크립트로 간단한 배치 파일을 작성했는데 실행 시 오류가 발생합니다.

내 경로의 스크립트 디렉토리에 있습니다.

Cannot be loaded because the execution of scripts is disabled on this system. 
please see "get-help about-signing".

도움말을 살펴봤지만 별로 도움이 되지 않습니다.

도움이 되었습니까?

해결책

(IIRC) 서명된 스크립트만 실행하는 PowerShell의 기본 보안 수준일 수 있습니다.

다음을 입력해 보세요.

set-executionpolicy remotesigned

그러면 PowerShell이 ​​로컬(즉, 로컬 드라이브에서) 서명되지 않은 스크립트의 실행을 허용하도록 지시합니다.

그런 다음 스크립트를 다시 실행해 보세요.

다른 팁

당신은 실행해야합니다 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.

사용:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

현재 세션에서 PowerShell을 실행하려면 항상 위 명령을 사용하세요.

다음과 같이 PowerShell을 호출하여 이 오류를 우회할 수 있었습니다.

powershell -executionpolicy bypass -File .\MYSCRIPT.ps1

즉, 나는 다음을 추가했습니다. -executionpolicy bypass 내가 스크립트를 호출하는 방식으로.

이것은 Windows 7 서비스 팩 1에서 작동했습니다.저는 PowerShell을 처음 사용하기 때문에 제가 알지 못하는 주의 사항이 있을 수 있습니다.

[2017-06-26 편집] Windows 10 및 Windows 2012 R2를 포함한 다른 시스템에서 이 기술을 문제 없이 계속 사용했습니다.

여기 제가 지금 사용하고 있는 것이 있습니다.이렇게 하면 실수로 스크립트를 클릭하여 스크립트가 실행되는 것을 방지할 수 있습니다.스케줄러에서 실행할 때 인수 하나를 추가합니다."스케줄러"이며 프롬프트를 우회합니다.

또한 마지막에 창이 일시 중지되어 PowerShell의 출력을 볼 수 있습니다.

if NOT "%1" == "scheduler" (
   @echo looks like you started the script by clicking on it.
   @echo press space to continue or control C to exit.
   pause
)

C:
cd \Scripts

powershell -executionpolicy bypass -File .\rundps.ps1

set psexitcode=%errorlevel%

if NOT "%1" == "scheduler" (
   @echo Powershell finished.  Press space to exit.
   pause
)

exit /b %psexitcode%
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

위 명령은 다음 오류가 발생하는 경우에도 효과적이었습니다.

Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.

또한 다음을 포함해야 할 수도 있다는 점을 아는 것이 좋습니다. .\ 스크립트 이름 앞에예를 들어:

.\scriptname.ps1

명령 set-executionpolicy unrestricted 생성한 모든 스크립트를 로그인한 사용자로 실행할 수 있습니다.다음을 사용하여 실행 정책 설정을 다시 서명으로 설정하세요. set-executionpolicy signed 로그아웃하기 전에 명령을 실행하세요.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top