Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute PowerShell Script from Grunt

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!

like image 914
user2871401 Avatar asked Nov 19 '13 17:11

user2871401


People also ask

How do I run a PowerShell script?

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.

How do I run a ps1 file from 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.

How do I run a PowerShell script from PowerShell?

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.

How do I run a PowerShell script in Linux?

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 .


1 Answers

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
like image 176
bevacqua Avatar answered Sep 19 '22 11:09

bevacqua