• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PowerShell Tools for DevOps

PowerShell Tools for DevOps

Gallery Downloads Build Status Build Status

PSDevOps helps you automate DevOps using PowerShell.

What is PSDevOps?

PSDevOps is a PowerShell module that makes it easier to automate DevOps with PowerShell.

What do you mean 'Easier to Automate'?

If you're familiar with PowerShell, you might know about the Object Pipeline.
This allows you to pass objects together, instead of parsing text at each step. While this is great, not many PowerShell commands or REST apis take full advantage of this feature.

PSDevOps does.

Almost every command in PSDevOps is pipeline-aware.
Related commands can often be piped together, and command results can often be piped back into a command to return additional information.

Additionally, PSDevOps output is often 'decorated' with extended type information.

This allows the PowerShell types and formatting engine to extend the return object and customize it's display.

Automate Azure DevOps

The Azure DevOps REST API can be challenging to work with, and hard to remember.

PSDevOps provides dozens of commands to automate Azure DevOps.

Commands are named simply and clearly, using PowerShell's verb-noun convention, for example, Get-ADOProject, Get-ADORepository, Get-ADOBuild

To see all commands from PSDevOps, run:

Get-Command -Module PSDevOps

Unlike many modules, these commands make use of the full feature set of PowerShell. Here are a few things PSDevOps does differently:

Using the Object Pipeline

The Object Pipeline is a core feature of PowerShell that allows you to send structured information from step to step.

Almost every function in PSDevOps is "pipeline aware", and can accept multiple types of objects

Connect-ADO -Organization $MyOrganization -PersonalAccessToken $MyPat
Get-ADOProject | Get-ADOTeam | Get-ADODashboard

Many commands can be piped back into themselves to return additional results, for instance:

Get-ADOBuild -Project MyProject -First 5 | # Get the first 5 builds 
    Get-ADOBuild -ChangeSet # Get the associated changesets.
Get-ADOAgentPool | # Gets agent pools from the organization
    Get-ADOAgentPool  # Gets individual agents within a pool, because the prior object returned a PoolID.

Invoke-ADORESTApi

In orer to ensure that you can always work with Azure DevOps, even if there isn't already a function in PSDevOps, there's Invoke-ADORestAPI.

Invoke-ADORestAPI can be used like Invoke-RESTMethod, and also has a number of additional features.

For instance:

  • -AsJob (Launch long-running queries as a job)
  • -Body (autoconverted to JSON)
  • -ExpandProperty (Expand out a particular property from output)
  • -PSTypeName (apply decoration to output)
  • -UrlParameter (Replace parameters within a URL)
  • -QueryParameter (Pass parameters within a querystring)

Help

Like any good PowerShell module, PSDevOps has help. Run Get-Help on any command to learn more about how to use it.

Get-Help Get-ADOBuild -Full

Commands that wrap the REST api should have a .LINK to the MSDN documentation on the API to help you understand what they are doing.

Custom Formatting

The Azure DevOps REST API can return a lot of unhelpful information. To make it easier to work with Azure DevOps in Powershell, PSDevOps includes several custom formatters.

For a simple example, try running one of the following commands:

Get-ADOProject
Get-ADOTeam -Mine

Extended Types

The Azure DevOps REST api often returns data that is inconsistently named or weakly typed.

Where possible, PSDevOps uses the Extended Type System in PowerShell to augment the values returned from Azure DevOps.

For example, when you run Get-ADOAgentPool, it will add two properties to the return value: PoolID (an alias to ID) and DateCreated (which converts the string date in .CreatedOn to a [DateTime]).

Supporting -WhatIf and -Confirm

Most commands in PSDevOps that change system state SupportShouldProcess, and have the automatic parameters -WhatIf and -Confirm.

-Confirm works the same in PSDevOps as it does in any PowerShell module. Passing -Confirm will always prompt for confirmation, and Passing -Confirm:$false will never prompt for confirmation.

PSDevOps does a bit better than most modules when it comes to supporting -WhatIf. In most modules, -WhatIf will write a message to the host about what might have run. In PSDevOps, passing -WhatIf should return the values about to be passed to the REST API.

New-ADOProject -Name Foo -Description bar -Confirm # Prompts for confirmation

New-ADOProject -Name Foo -Description bar -WhatIf  # Returns the data that would be passed to the REST endpoint. 

Creating Complex Pipelines

While Azure DevOps templates are nice, they don't give you syntax highlighting for the scripts of each step.
Also, cross-repository templates can be painful.

PSDevOps allows you to create Azure DevOps pipelines using New-ADOPipeline.

For instance, this create a cross-platform test of the current repository's PowerShell module.

New-ADOPipeline -Job TestPowerShellOnLinux, TestPowerShellOnMac, TestPowerShellOnWindows

This creates a multistage pipeline that does PowerShell static analysis, tests the current module (crosssplatform), and updates the PowerShell gallery using a Secret:

New-ADOPipeline -Stage PowerShellStaticAnalysis, TestPowerShellCrossPlatform, UpdatePowerShellGallery

This little one liner works wonderfully to build a CI/CD pipeline in Azure DevOps around almost any PowerShell modules.

Parts are stored in a \ado\PartName\ as either a .ps1 or a .psd1 file. PS1 files will implicitly become script tasks. PSD1 files will be treated as task metadata, and can reference other parts.

Any module that contains an \ADO directory and is tagged 'PSDevOps' or requires PSDevOps can contain parts. Parts found in these modules will override parts found in PSDevOps.

Advanced Azure DevOps Pipeline Logging

PSDevOps can also be used to help you write information to the a pipeline's timeline. This can be considerably easier than memorizing the Logging Commands Documentation.

PSDevOps makes this much nicer by abstracting away this ugliness into easy-to-use commands:

  • Add-ADOAttachment
  • Set-ADOBuild
  • Set-ADOEndpoint
  • Set-ADOVariable
  • Write-ADOError
  • Write-ADOProgress
  • Write-ADOWarning

Dealing with DevOps

DevOps is a hybrid discipline combining the skillset of Devolopers and Operations.
With DevOps, the focus is on automation, and PowerShell is often the language of choice.

By convention, most developers write their scripts according to a psuedostandard:

*-*.ps1 Scripts containing a function
*.*.ps1 'Special' Scripts, often used by particular modules *.ps1 Simple scripts that are run interactively.

PSDevOps has a command, Get-PSDevOps, that helps to identify these scripts and their requirements.

Get-Module PSDevOps | Get-PSDevOps

PSDevOps GitHub API

PSDevOps also provides a few functions to work with the GitHub API.

  • Connect/Disconnect-GitHub
  • Invoke-GitHubRESTAPI

Invoke-GitHubRESTAPI works like Invoke-ADORestAPI, as a general-purpose wrapper for GitHub REST API calls.

It also has a number of additional features, for example:

  • -AsJob (Launch long-running queries as a job)
  • -Body (autoconverted to JSON)
  • -ExpandProperty (Expand out a particular property from output)
  • -PSTypeName (apply decoration to output)
  • -UrlParameter (Replace parameters within a URL)
  • -QueryParameter (Pass parameters within a querystring)

Because GitHub's REST api is predictable and exposed with OpenAPI, Invoke-GitHubRESTAPI also enables two very interesting scenarios:

  1. Connect-GitHub can automatically create a shortcut for every endpoint in the GitHub API
  2. Invoke-GitHubRESTAPI can automatically decorate return values more apporopriately.

This means that PSDevOps can integrate with GitHub's REST API with a very small amount of code, and easily customize how GitHub output displays and works in PowerShell.

Write GitHub Actions

You can automatically generate GitHub actions off of any PowerShell script or command.

First, create a /GitHub/Actions folder in your module directory, then put one or more .ps1 files in it.

Then,

Import-BuildStep -ModuleName YourModule

Then, you can generate your action.yml with some code like this.

New-GitHubAction -Name "Name Of Action" -Description 'Action Description' -Action MyAction -Icon minimize -ActionOutput ([Ordered]@{
    SomeOutput = [Ordered]@{
        description = "Some Output"
        value = '${{steps.MyAction.outputs.SomeOutput}}'
    }    
})

Write GitHub Workflows

You can use PSDevOps to write complex Github Workflows using the same techniques as Azure DevOps pipelines:

New-GitHubWorkflow -Name RunPester -On Demand, Push, PullRequest -Job TestPowerShellOnLinux

As with Azure DevOps, parts of the workflow can be defined within the \GitHub subdirectory of PSDevOps or any module.

Advanced GitHub Workflow Logging

PSDevOps also includes commands to make logging within a GitHub workflow easier. They are:

  • Hide-GitHubOutput
  • Write-GitHubDebug
  • Write-GitHubError
  • Write-GitHubOutput
  • Write-GitHubWarning

More Repositories

1

Irregular

Regular Expressions made Strangely Simple
PowerShell
95
star
2

PipeScript

A Metaprogramming Language for PowerShell (and anything else)
PowerShell
81
star
3

ugit

Updated Git: A powerful PowerShell wrapper for git that lets you extend git, automate multiple repos, and output git as objects.
PowerShell
70
star
4

Pipeworks

PowerShell Pipeworks is a web platform built in Windows PowerShell, and a toolkit for putting it all together with PowerShell
PowerShell
70
star
5

Splatter

Simple Scripts to Supercharge Splatting
PowerShell
62
star
6

EZOut

EZOut is a PowerShell module to help take the pain out of writing format and types XML
PowerShell
58
star
7

PowerArcade

A Retro Arcade Game Console in PowerShell
PowerShell
54
star
8

Posh

PowerShell made Posh
PowerShell
54
star
9

Benchpress

Easy Benchmarking with PowerShell
PowerShell
52
star
10

obs-powershell

Script OBS with PowerShell
PowerShell
49
star
11

ScriptCop

ScriptCop is a static analysis and testing tool for Windows PowerShell
PowerShell
39
star
12

ShowDemo

A simple tool to showcase your scripts.
PowerShell
37
star
13

ScriptDeck

PowerShell Tools for Elgato StreamDeck
PowerShell
36
star
14

Eventful

Easy Eventful PowerShell
PowerShell
32
star
15

RoughDraft

A Fun PowerShell Module for Multimedia (using FFMpeg)
PowerShell
30
star
16

PSSVG

Script SVGs with PowerShell
PowerShell
29
star
17

HelpOut

A Helpful Toolkit for Managing PowerShell Help
PowerShell
26
star
18

Patchy

Patchy is a PowerShell module that helps smooth out the chop of maintaining Windows Updates
PowerShell
25
star
19

PSMinifier

A Miniature Minifier For PowerShell
PowerShell
19
star
20

MenuShell

MenuShell is a PowerShell module for rapidly making console menus
PowerShell
19
star
21

TerminalVelocity

Fine tuning Windows Terminal
PowerShell
18
star
22

LightScript

Smarter Lighting with PowerShell
PowerShell
17
star
23

Discovery

Discovery is a powerful PowerShell module that lets you probe the inner depths of the operating system.
PowerShell
16
star
24

OnQ

Easy Asynchronous Event-Driven Scripting with PowerShell
PowerShell
16
star
25

PowerNix

Linux Tools for PowerShell People.
PowerShell
15
star
26

AutoBrowse

AutoBrowse is a Windows PowerShell module that lets you automate browsing with Internet Explorer
PowerShell
15
star
27

Rocker

Rock Docker with PowerShell
PowerShell
14
star
28

PowerHistory

PowerShell History Made More Powerful
PowerShell
12
star
29

Piecemeal

Easy Extensible Plugins for PowerShell
PowerShell
12
star
30

CodeCraft

CodeCraft is a Powershell module full of code generators that helps you crank out tedious code.
PowerShell
12
star
31

PowerShellAI

PowerShell meets GPT - Artificial Intelligence
PowerShell
12
star
32

Emoji

⟩⚑PowerShell Emoji πŸ˜ŽπŸ˜‰πŸ˜πŸ₯°πŸ€”πŸ˜Ÿ
PowerShell
10
star
33

PSMetrics

A Module for Metrics in PowerShell
PowerShell
9
star
34

PSPrettifier

Prettify your PowerShell
PowerShell
9
star
35

PingMe

PingMe is a PowerShell module to simplify different types of network checks on a machine
PowerShell
9
star
36

GitPub

Easily Automate Publishing from GitHub
PowerShell
8
star
37

Winformal

Winformal is a PowerShell module to let you script WinForms with cmdlets
PowerShell
8
star
38

SecureSettings

SecureSettings is a small PowerShell module to manage storing settings information securely
PowerShell
7
star
39

HeatMap

HeatMap is a PowerShell module for monitoring performance counters in PowerShell
PowerShell
7
star
40

StartAutomating

Save Time, Save Money, Start Automating.
PowerShell
7
star
41

PowerCode

A PowerShell Module for Customizing Visual Studio Code
PowerShell
6
star
42

PSA

PowerShell Announcements (with AtProtocol)
PowerShell
5
star
43

PoshMacros

Sleek and Simple PowerShell Macros
PowerShell
5
star
44

PowRoku

Script your Roku with PowerShell
PowerShell
4
star
45

TerminalTunes

A Music Player for Terminals
PowerShell
3
star
46

PS3D

PowerShell Tools for 3D Printing
PowerShell
3
star
47

PSData

In-Memory .NET Databases in PowerShell
2
star
48

PowerShellPowerPoints

A Collection of Presentations I've given on PowerShell
PowerShell
2
star
49

formulaic

Formulaic is a PowerShell module containing useful math, physics, and statistcs functions
PowerShell
1
star
50

StartAutomating.github.io

Save Time, Save Money, Start Automating.
1
star