GitHub Copilot for the Windows systems administrator

Created on January 22, 2023 at 4:51 pm

Category: Programming


Learn how the AI-powered GitHub Copilot pair programming engine can accelerate your Windows administration work by providing intelligent suggestions while you type.

Why would you, a Windows systems administrator, want to use an artificial intelligence (AI)-based pair programming engine like GitHub Copilot? Well, let me answer that question by asking another question: How many of the following languages and command-line interfaces (CLIs) do you use in your daily work?

  • PowerShell
  • Bash
  • Git
  • Azure CLI
  • Amazon Web Services (AWS) CLI
  • Python

I think you’ll be impressed with how dramatically GitHub Copilot can accelerate your administrative automation coding. In case you don’t know, GitHub Copilot is a paid cloud service that uses the OpenAI Codex, a powerful machine learning (ML) model. GitHub and OpenAI continually train the model to refine the suggestions it can generate from conversational user input.

By the way, this is the same OpenAI that developed the ChatGPT chatbot that’s created such a news buzz over the past weeks and months.

With regard to billing, you should start with the 60-day free trial and then consider boosting your trial to a paid tier. As of late December 2022, GitHub Copilot costs $10 USD per month or $100 USD per year. However, you should read the GitHub Copilot billing page I linked to in the previous paragraph because you very well may qualify for free usage. Because I host several open-source repositories at GitHub, I use Copilot with no charge myself.

Set up your GitHub Copilot environment

Here’s the three-step workflow to get started with GitHub Copilot:

  1. Sign up for the service at GitHub.com.
  2. Install the Visual Studio Code GitHub Copilot extension.
  3. Ensure Visual Studio Code recognizes your file types.

Once you have completed the previous steps, you are ready for takeoff with GitHub Copilot as your AI pair programmer. Note you can toggle Copilot on or off by using its status bar button, as shown in the following screenshot.

Comment-based suggestions

As long as VS Code recognizes your file type, that’s all you need to begin. In this tutorial, I’m using PowerShell, so I installed the PowerShell VS Code extension to give me native language support. I also ensured my file extension is .ps1, and VS Code recognizes that I’m writing PowerShell via the Language Mode button.

Comment-based suggestions are generated by GitHub Copilot when you use that language’s line comment symbol (# in PowerShell) and type what you want to do. Yes, it’s that easy.

For example, try the following example in your VS Code editor:

# Create Active Directory users from a CSV file

Make sure to press CTRL+ENTER at the end of your comment. This keystroke instructs Copilot to synthesize 10 solutions from which you can pick and choose. Clicking the CodeLens Accept Solution link does two things:

  1. Adds that suggestion to the cursor location in your current work file
  2. Contributes to training the OpenAI Codex model’s accuracy

Do you work with Git source code management? I don’t know about you, but that Git syntax is pretty muddy, to say the least. GitHub Copilot can help you answer your Git questions simply and easily.

For example, I added this comment and pressed CTRL+ENTER:

# Show me the last five Git commits in descending order

GitHub Copilot immediately generated the following suggestion, which worked great for me:

git log –pretty=oneline –abbrev-commit -5

Are you getting the hang of it? One more example: Let’s assume you were tasked with creating a Windows PowerShell Desired State Configuration (DSC) script to describe an IIS web server with associated site content.

How do you normally remember the DSC configuration syntax? Stack Overflow, right? Not anymore. Try something like the following example and see what GitHub Copilot suggests:

# IIS DSC configuration including sample content

Context-based suggestions

The second way to use GitHub Copilot is to enable the tool to give you suggestions while you type. For example, let’s say you need to write a PowerShell function that creates an MD5 cryptographic hash based on string input.

As long as you name your function descriptively enough, GitHub Copilot will make suggestions for you immediately, as shown in the following screenshot.

As you can see, my naming the function Create-MD5Hash gave GitHub Copilot inspiration enough to provide a suggested code completion. At this point, I can take any of these actions:

  • Press ESC to dismiss Copilot
  • Press TAB to accept the suggestion
  • Press ALT+] to move to the next suggestion
  • Press ALT + [ to move to the previous suggestion

Isn’t that awesome? Now it (almost) goes without saying, but allow me to say it anyway: Please inspect any code GitHub Copilot suggests for you. You don’t want to blindly accept the suggestion and integrate it into your production work, unless, and until you’ve validated it.

Now, you may like GitHub Copilot’s inline suggestions enough that you’ll configure your VS Code language extension to disable its own IntelliSense. For our final example, type the following PowerShell command, and press CTRL+ENTER to see Copilot’s synthesized code completers:

New-SelfSignedCertificate –

Privacy concerns

You might be wondering:

  • Where does GitHub Copilot get its training data?
  • Does the code GitHub Copilot generates exist in a GitHub repository somewhere?
  • Does GitHub Copilot steal my code?

These are all logical, understandable questions, for sure. I’d suggest that you read the GitHub Copilot FAQ, but here are some general points I found out for you.

GitHub does not own any code it generates. If you use a suggestion, it’s your code and your responsibility to maintain it. GitHub Copilot collects general usage and error data constrained to your work in Visual Studio Code with Copilot. Your own source code is not “scraped” and integrated into the OpenAI Codex machine learning model.

However, you should know that the open-source code you host at GitHub is included in the Codex training set.

Subscribe to 4sysops newsletter!

I hope you find GitHub Copilot to be as much of a boon to your productivity as I do. Let us know what you think in the comments!

Connecting to lzomedia.com... Connected... Page load complete