General

Git integration for Power Actions

Ever since we introduced Power Actions back in April, one of the most frequently asked questions we get from our customers is whether we plan to integrate with source control systems like Git. While we still don’t have that out-of-the-box in Power Actions, in this blog post, I’ll show you how to easily create a script that you can run with Power Actions to sync your script library with a Git folder.

Let’s get started.

Since Git is not available out-of-the-box in Power Actions, the first thing we need to do in our script is to install Git.


The next step is to pull the scripts that we want from Git to our machine. In this sample script, we’ll sync our script library with the PowerActions folder in the PowerCLI sample scripts repo on GitHub (https://github.com/vmware/PowerCLI-Example-Scripts/tree/master/PowerActions).


Now that we have the scripts from the Git repo, the next step is to check what we have in our script library. Since the script library is actually backed by a content library, we’ll use the PowerCLI cmdlets for content library to do this. For every script that we have retrieved from Git, we’ll check if a script with the same name already exists in the script library. If it doesn’t, that means we have to upload it there using the New-ContentLibraryItem cmdlet. If it already exists in the script library, we’ll download it from there and compare it with the file that we have retrieved from Git. No action is needed if the files are identical. However, if the file that we have downloaded from Git is different, we’ll update the script in the script library.

And that’s it!

Using this script you can sync your script library with a Git folder. This way, you can easily keep your scripts up to date and share them with your team. You can also customize this script to work with other source control systems or other repos and folders.

You can find the script in the PowerActions folder in the PowerCLI sample scripts repo on GitHub. I hope you found this blog post useful and learned something new. Happy scripting!