简体   繁体   中英

Is it possible to call powershell command from within Cake task

I'm switching from Psake build tool to Cake ( https://cakebuild.net/ ). I'm creating a scripts for quite big solution (30+ projects) with (currently) 9 different deploys. In Psake it was trivial to call PowerShell commands, since entire script has been running in powershell.

But now I have a problem. I have to call some commands that are running in PS, but I can't find a way to execute them.

Some examples:

taskkill /IM iisexpress.exe
Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Stop-Website <'name of website'>}
Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Start-Website <'name of website'>}

I've tried with StartAndReturnProcess (example: StartAndReturnProcess("taskkill /IM iisexpress.exe"); ), but without success. I've also found Cake.IIS plugin, which would probbably solve my issues with starting and stopping IIS, but there are also smoe other PS commands that I'd like to invoke.

Is it possible to simple call a PowerShell command from Task? Something like this:

Task("DoSomeMagic")
    .Does(() =>
{

    ExecutePowerShellCommad("taskkill /IM iisexpress.exe");
    ExecutePowerShellCommad("Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Stop-Website <'name of website'>}");

    //ToDo: other magic
});

Thanx for any answer and best regards, Martin

Have you seen the Cake.PowerShell addin?

Example usage can be found here , but to provide an example (taken from readme):

#addin "Cake.Powershell"

Task("Powershell-Script")
    .Description("Run an example powershell command with parameters")
    .Does(() =>
{
    StartPowershellScript("Write-Host", args =>
        {
            args.AppendQuoted("Testing...");
        });
});

There are more complicated examples in the readme depending on exactly what you are trying to achieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM