본문 바로가기

PC팁

Windows PowerShell script file(*.ps1) 실행

반응형

확장자가 ps1인 Windows PowerShell Script file을 실행하려고하면 아래와 같이 오류가 발생하는 경우가 있습니다.

PS C:\~~~~> npm install -g firebase-tools
npm : 이 시스템에서 스크립트를 실행할 수 없으므로 C:\Program Files\nodejs\npm.ps1 파일을 로드할 수 없습니다. 자세한
내용은 about_Execution_Policies(https://go.microsoft.com/fwlink/?LinkID=135170)를 참조하십시오.
위치 줄:1 문자:1
+ npm install -g firebase-tools
+ ~~~
    + CategoryInfo          : 보안 오류: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

 

위 오류는 Windows PowerShell의 기본 실행 정책(Execution Policy) 때문에 발생하는 것으로, 보안상의 이유로 스크립트 실행을 차단하고 있습니다. PowerShell의 실행 정책을 변경해야합니다.

 

1. PowerShell을 관리자 권한으로 실행합니다.

  • 시작 메뉴에서 "PowerShell"을 검색
  • "Windows PowerShell"을 우클릭하고 "관리자 권한으로 실행" 선택

2. 하기와 같이 입력하여 실행 정책을 RemoteSigned로 변경

Set-ExecutionPolicy RemoteSigned

 

이제 ps1 file을 실행하면 정상적으로 실행되는 것을 확인할 수 있습니다.

PS C:\Users\~~~~> npm
npm <command>

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term> (in a browser)
npm help npm       more involved overview (in a browser)

All commands:

    access, adduser, audit, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    help-search, hook, init, install, install-ci-test,
    install-test, link, ll, login, logout, ls, org, outdated,
    owner, pack, ping, pkg, prefix, profile, prune, publish,
    query, rebuild, repo, restart, root, run-script, sbom,
    search, set, shrinkwrap, star, stars, start, stop, team,
    test, token, uninstall, unpublish, unstar, update, version,
    view, whoami

Specify configs in the ini-formatted file:
    C:\Users\jjoey\.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

npm@10.9.3 C:\Program Files\nodejs\node_modules\npm
반응형