I have a PowerShell script (myScript.ps1) that I need to run as part of my build process. I'm using Grunt to build my code. I cannot figure out how to run this script from Grunt. Does anyone know how to run a PowerShell script from Grunt such that the next task won't run until the PowerShell script has completed?
Thank you!
Run File Explorer, right-click the script filename and then select "Run with PowerShell". The "Run with PowerShell" feature is designed to run scripts that do not have required parameters and do not return output to the command prompt.
ps1 files are interpreted by PowerShell, the Command Prompt (CMD) cannot work with PowerShell scripts directly. If you would like to run a PowerShell script in CMD, you'll need to execute it by calling the PowerShell process with the -File parameter, as shown below: PowerShell -File C:\TEMP\MyNotepadScript. ps1.
In File Explorer (or Windows Explorer), right-click the script file name and then select "Run with PowerShell". The "Run with PowerShell" feature starts a PowerShell session that has an execution policy of Bypass, runs the script, and closes the session.
Running Basic PowerShell Commands on Linux To start PowerShell, simply run pwsh and you'll be dropped into the PowerShell interactive console. Being a cross-platform scripting language, PowerShell on Linux supports all of the commonly known commands from CMD and Linux's command line shell such as sudo apt update .
You could give a try to grunt-shell
Install
npm install --save-dev grunt-shell
Load
grunt.loadNpmTasks('grunt-shell');
Configure
grunt.initConfig({
shell: {
ps: {
options: {
stdout: true
},
command: 'powershell myScript.ps1'
}
}
});
Use
grunt shell:ps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With