간단한 배치 파일을 PowerShell 스크립트로 작성했는데 실행시 오류가 발생합니다.
내 경로의 스크립트 디렉토리에 있습니다. 이것은 내가 얻는 오류입니다.
이 시스템에서 스크립트 실행이 비활성화되어 있으므로로드 할 수 없습니다. "서명에 대한 도움말 얻기"를 참조하십시오.
도움말을 살펴 봤지만 도움이되지 않았습니다.
간단한 배치 파일을 PowerShell 스크립트로 작성했는데 실행시 오류가 발생합니다.
내 경로의 스크립트 디렉토리에 있습니다. 이것은 내가 얻는 오류입니다.
이 시스템에서 스크립트 실행이 비활성화되어 있으므로로드 할 수 없습니다. "서명에 대한 도움말 얻기"를 참조하십시오.
도움말을 살펴 봤지만 도움이되지 않았습니다.
답변:
PowerShell의 기본 보안 수준 일 수 있으며 (IIRC)는 서명 된 스크립트 만 실행합니다.
다음을 입력 해보십시오.
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 등 다른 시스템에서도이 기법을 문제없이 계속 사용하고 있습니다.
지금 내가 사용하고있는 것은 다음과 같습니다 이렇게하면 스크립트를 클릭하여 실수로 스크립트를 실행할 수 없습니다. 스케줄러에서 실행할 때 "scheduler"라는 인수를 추가하면 프롬프트를 우회합니다.
또한 마지막에 창을 일시 중지하여 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.
이 명령 set-executionpolicy unrestricted
을 사용하면 작성한 모든 스크립트가 로그인 한 사용자로 실행됩니다. set-executionpolicy signed
로그 아웃하기 전에 명령을 사용하여 실행 정책 설정을 다시 서명으로 설정해야합니다 .
set-executionpolicy signed
제공 Cannot bind parameter 'ExecutionPolicy'
등
Windows 10의 경우 : myfile.ps1의 보안 속성 변경을 클릭하고 myfile.ps1의 속성을 마우스 오른쪽 버튼으로 클릭하여 "액세스 허용"을 변경합니다.