SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

Cake.Powershell

Cake-Build addin that extends Cake with Powershell commands

cakebuild.net

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

Table of contents

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

Implemented functionality

Continuous integration

Build server Platform Build status
AppVeyor Windows AppVeyor
Travis Linux / MacOS Travis

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

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 :star: the repository.