PowerShell: OpenAI Integration (CoPilot, GPT-3, DALL•E & More)

Have you ever wanted to ask ChatGPT something while coding in your PowerShell terminal or just streamline your coding workflow and search for information without ever leaving your PowerShell terminal. Or simply just too lazy to leave your focus outside of the Console Window and navigate to ChatGPT on the web? 🤔

Well, look no further than “PowerShell AI” created by Doug Finke (Microsoft MVP) and contributed by the Community – the module that allows you to integrate your OpenAI account directly into your console window! In this post, we’ll show you how to install and set up this powerful tool, so you can utilize ChatGPT, code, and innovate all without breaking your concentration.

Today, we’re going to have some fun and integrate OpenAI API with your PowerShell Terminal! ⬛.

Get ready to revolutionize your PowerShell experience and let’s dive in!


  • An OpenAI account with an available token key
  • Access to install modules in PowerShell

Installing the PowerShell AI module

Open your favourite console window with administrator access, “Shift” + “Right-click” to get the “Run as administrator” option available.

Install the module by running the following line:

Install-Module -Name PowerShellAI

Configure the OpenAI account

Configure your OpenAI API Token Key with the following line:

$env:OpenAIKey = "Your_OpenAPI_Key"

Using the PowerShell AI Module

GPT-3 – Prompt Generator

This is an example of what I would ask myself when my head wanders off at work, right after my lunch breaks…

ai "Your_Question"

DALL•E – Picture Generator

Get-DalleImage "You_Imagination_Is_Endless"

You can then navigate to the folder path where the picture is produced to view it.

Awww… Almost had it… 😂

There’s also a command which can set generated pictures as a wallpaper background:


CoPilot – Code Generator

This is a question that could help the IT-support for every company. Through running such a script remotely on the user’s computer, instead of having an endless conversation about what the label says on their Display bezel… (I still believe that this is a very difficult question for non-technical people to answer in 2023).

copilot "Your_Code_Question"

AI – Error Helper

This is one of my favourite functions! An AI-tool that takes your last error message and hints at what could be wrong and what would help resolving the error!

ChatGPT – Create Excel Spreadsheet based on prompts

This one needs the additional Module to work with Excel workbooks:

Install-Module -Name ImportExcel

Ask PowerShell AI in your PowerShell console to populate the spreadsheet, based on your prompt. Example:

New-Spreadsheet 'Ingredients to make Norwegian Fastelavnsbolle'

Here’s a great video demonstration as well, published by the creator:

New-Spreadsheet – PowerShell + ChatGPT + Excel – YouTube

Get a list of other functions

There’s also a list of other functions that you could use and play with, but I’m not gonna go into each and everyone of them, so feel free to experiment them all yourself!🕵️‍♂️

Get-Command -Module PowerShellAI

Below is a list of available descriptions for the different functions:

PS ScriptDescription
Disable-AIShortCutKeyDisable the ctrl+g shortcut key go getting completions
Enable-AIShortCutKeyEnable the ctrl+g
Get-OpenAIEditGiven a prompt and an instruction, the model will return an edited version of the prompt
Get-GPT3CompletionGet a completion from the OpenAI GPT-3 API
Get-DalleImageGet an image from the OpenAI DALL-E API
Experimental AI function that you can pipe all sorts of things into and get back a completion
copilotMakes the request to GPT, parses the response and displays it in a box and then prompts the user to run the code or not.
Set-DalleImageAsWallpaperSet the image from the OpenAI DALL-E API as the wallpaper
Invoke-AIErrorHelperHelper function let ChatGPT add more info about errors
Get-OpenAIUsageReturns a billing summary of OpenAI API usage for your organization

For more information about this Module and how the functions scripts has been built, have a look at the creator Doug Finke’s GitHub – Huge shoutout to him! ❤️

dfinke/PowerShellAI: PowerShell AI module for OpenAI GPT-3 and DALL-E (github.com)






Leave a Reply

Your email address will not be published. Required fields are marked *