IT

내 PowerShell 펼쳐가 실행되지 않는 이유는 무엇입니까?

lottoking 2020. 8. 26. 08:11
반응형

내 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.

또한 .\펼쳐 이름 앞에 포함해야 우리 할 수도 있음을 아는 것이 좋습니다 . 예를 들면 :

.\scriptname.ps1

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


Windows 10 : myfile.ps1의 보안 속성 변경을 클릭하고 myfile.ps1에서 마우스 오른쪽 버튼을 클릭하여 "액세스 허용"을 변경합니다.

참고 URL : https://stackoverflow.com/questions/10635/why-are-my-powershell-scripts-not-running

반응형