/Cake.Powershell

Powershell addin for Cake

Primary LanguageC#MIT LicenseMIT

Cake.Powershell

Cake-Build addin that extends Cake with Powershell commands

Build status

cakebuild.net

Join the chat at https://gitter.im/cake-build/cake

Table of contents

  1. Implemented functionality
  2. Referencing
  3. Usage
  4. Example
  5. TroubleShooting
  6. Plays well with
  7. License
  8. Share the love

Implemented functionality

  • Local / remote scripts
  • Script files
  • Download and run remote script file
  • Script parameters
  • Outputting to the cake console

Referencing

NuGet Version NuGet Downloads

Cake.Powershell is available as a nuget package from the package manager console:

Install-Package Cake.Powershell

or directly in your build script via a cake addin directive:

#addin "Cake.Powershell"

Usage

#addin "Cake.Powershell"

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

Task("Powershell-Script-Settings")
    .Description("Run an example powershell command with settings and parameters")
    .Does(() =>
{
    StartPowershellScript("Get-Process", new PowershellSettings()
        .SetFormatOutput()
        .SetLogOutput()
        .WithArguments(args =>
        {
            args.AppendQuoted("svchost");
        }));
});


Task("Powershell-File")
    .Description("Run an example powershell script file with parameters")
    .Does(() =>
{
    StartPowershellFile("../Scripts/Install.ps1", args =>
        {
            args.Append("Username", "admin")
                .AppendSecret("Password", "pass1");
        });
});

Task("Powershell-File-Settings")
    .Description("Run an example powershell script file with settings and parameters")
    .Does(() =>
{
    StartPowershellFile("../Scripts/sql.ps1", new PowershellSettings()
        .WithModule("sqlps")
        .WithArguments(args =>
        {
            args.Append("Username", "admin")
                .AppendSecret("Password", "pass1");
        }));
});


Task("Powershell-Remote-Script")
    .Description("Run an example powershell command remotely")
    .Does(() =>
{
    StartPowershellScript("Get-Services", new PowershellSettings()
    {
        ComputerName = "remote-location",
        Username = "admin",
        Password = "pass1",

        FormatOutput = true,
        LogOutput = true
    });
});

Task("Powershell-Remote-File")
    .Description("Run an example powershell file remotely")
    .Does(() =>
{
    StartPowershellFile("C:/Scripts/sql.ps1", new PowershellSettings()
        {
            ComputerName = "remote-location",
            Username = "admin",
            Password = "pass1",

            FormatOutput = true,
            LogOutput = true
        }.WithArguments(args =>
        {
            args.Append("task", "do-what-i-say");
        }));
});



Task("Powershell-Download")
    .Description("Run an example powershell script file after downloading its contents to a local directory")
    .Does(() =>
{
    StartPowershellDownload("https://chocolatey.org/install.ps1", "C:/Temp/install.ps1", new PowershellSettings());
});

RunTarget("Powershell-Script");

Example

A complete Cake example can be found here.

TroubleShooting

  • Please be aware of the breaking changes that occurred with the release of Cake v0.22.0, you will need to upgrade Cake in order to use Cake.Powershell v0.4.0 or above.

A few pointers for correctly enabling powershell scripting can be found here.

Plays well with

If your looking for a way to trigger cake tasks based on windows events or at scheduled intervals then check out CakeBoss.

License

Copyright (c) 2015 - 2016 Phillip Sharpe

Cake.Powershell is provided as-is under the MIT license. For more information see LICENSE.

Share the love

If this project helps you in anyway then please the repository.