how to execute powershell ps1 scripts from package.json "scripts"? how to execute powershell ps1 scripts from package.json "scripts"? powershell powershell

how to execute powershell ps1 scripts from package.json "scripts"?


Assuming powershell is in you PATH you can call it like this:

"scripts": {    "test": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./test.ps1"}

Tested on Windows 7 with Powershell v4.

Limitations are that you need Powershell installed and in your PATH. I didn't test it with Powershell for Linux, so not sure if this solution will be portable to other platform for now.


You might set the script-shell config - either via npm config set script-shell "powershell" or environment variable $env:npm_config_script_shell="powershell"

Then you could use

"scripts": {    "test": "Write-Host 'this is only a test'"}

or

"scripts": {    "buildAngular": ".\\buildAngular.ps1"}

I'm not sure whether you can supply parameters like -NoProfile though.


Prepend the PowerShell command with "powershell", e.g.,

"command": "powershell Remove-Item ..\\folder\\file; Copy-Item -Path folder\\* -Destination ..\\other-folder -Recurse",
"buildAngular": "powershell buildAngular.ps1"