Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set PowerShellAI OpenAI API Credentials Securely on Windows. Associated blogpost
# 1. Get API Credential via prompt.
# Only need the password which is your API Key
$gptAPI = Get-Credential
# 2. Export to a file in the local directory
$gptAPI | Export-Clixml ./chatGPTAPIKey.xml
# 3. Ongoing you only need to put the following two lines at the top of your scripts
# Make sure you copy your chatGPTAPIKey.xml file to other directories for scripts for OpenAI.
$chatGPTCred = Import-Clixml .\chatGPTAPIKey.xml
$chatGPTAPIKey = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($chatGPTCred.Password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment