Skip to content

Instantly share code, notes, and snippets.

View darrenjrobinson's full-sized avatar

Darren Robinson darrenjrobinson

View GitHub Profile
View Start PowerShellAI OpenAI Content GUI.ps1
# 1. Import the OpenAI API Key from the local securely exported credential
$chatGPTCred = Import-Clixml .\chatGPTAPIKey.xml
# 2. Use the Set-OpenAIKey cmdlet to take the secure credential and set the OpenAIKey environment variable
Set-OpenAIKey -Key $chatGPTCred.Password
# 3. Import the PowerShellAI Module
Import-Module PowerShellAI
# 4. Start the GUI
@darrenjrobinson
darrenjrobinson / Simplified Set PowerShellAI OpenAI API Credential.ps1
Last active April 26, 2023 00:20
Simplified Set PowerShellAI OpenAI API Credentials Securely on Windows. Associated blogpost https://blog.darrenjrobinson.com/generative-ai-chatgpt-with-powershell/
View Simplified Set PowerShellAI OpenAI API Credential.ps1
# 1. Import the OpenAI API Key from the local securely exported credential
$chatGPTCred = Import-Clixml .\chatGPTAPIKey.xml
# 2. Use the Set-OpenAIKey cmdlet to take the secure credential and set the OpenAIKey environment variable
Set-OpenAIKey -Key $chatGPTCred.Password
# 3. Import the PowerShellAI Module
Import-Module PowerShellAI
@darrenjrobinson
darrenjrobinson / Set PowerShellAI OpenAI API Credential.ps1
Last active April 26, 2023 00:21
Set PowerShellAI OpenAI API Credentials Securely on Windows. Associated blogpost https://blog.darrenjrobinson.com/generative-ai-chatgpt-with-powershell/
View Set PowerShellAI OpenAI API Credential.ps1
# 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
View Update SuccessFactors Email Address including isPrimary.ps1
$Global:headers = $null
$Global:SSFBaseURI = "https://api10preview.sapsf.com/odata/v2/"
$Global:SSFBusinessEmailType = "159139"
$Global:SSFPersonalEmailType = "159140"
Function Connect-SSF {
[cmdletbinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$SSFBaseURI
View Query Microsoft Graph with Python and Decode AAD Access Token.py
import msal
import jwt
import json
import sys
import requests
from datetime import datetime
global accessToken
global requestHeaders
global tokenExpiry
View WordPress API Authentication.ps1
# V2 APIs
# Basic AuthN
$userID = 'yourWordpressAccountAlias'
$userPassword = 'ABCD wTUZ pIST 9jEo 99LV 1234'
$Bytes = [System.Text.Encoding]::utf8.GetBytes("$($userID):$($userPassword)")
$encodedAuth = [Convert]::ToBase64String($Bytes)
$header = @{Authorization = "Basic $($encodedAuth)" }
Invoke-RestMethod -method get -uri "https://yourwordpressURL/wp-json/wp/v2/posts" -headers $header
@darrenjrobinson
darrenjrobinson / MSGraph AuthCode with PKCE.ps1
Last active December 21, 2021 20:08
Connecting to Microsoft Graph using the Authorization Code with PKCE Flow and PowerShell. Associated blogpost https://blog.darrenjrobinson.com/connecting-to-microsoft-graph-using-the-authorization-code-with-pkce-flow-and-powershell/
View MSGraph AuthCode with PKCE.ps1
import-module PKCE
import-module JWTDetails
$clientID = '<your AAD clientID>'
$tenantID = '<your AAD tenantID'
$clientSecret = '<your AAD App Client Secret>'
$replyURL = 'https://localhost/'
$scopes = 'user.read.all'
Function Get-AuthCode {
@darrenjrobinson
darrenjrobinson / Get Microsoft Graph Permission Scope IDs.ps1
Last active November 18, 2021 23:14
Get Microsoft Graph Permission Scope IDs using a PowerShell Azure Cloud Shell CLI. Associated blogpost https://blog.darrenjrobinson.com/microsoft-graph-permission-scope-ids/
View Get Microsoft Graph Permission Scope IDs.ps1
# Get Service Principals
$spList = az ad sp list --all
$spListObj = $spList | ConvertFrom-Json
# Get Graph Permissions
$graphSP = $spListObj | Where-Object {$_.appID -eq '00000003-0000-0000-c000-000000000000'} | Select-Object
# List of Application Scopes
$adminScopes = $graphSP.oauth2Permissions | Where-Object {$_.type -eq 'Admin'} | Sort-Object value | Select-Object id, isEnabled, type, adminConsentDescription, adminConsentDisplayName, value
@darrenjrobinson
darrenjrobinson / Get AAD FIDO2 Token Details.ps1
Last active October 6, 2021 23:58
Get FIDO2 Tokens Azure Active Directory Passwordless configuration details using PowerShell. Associated blogpost https://blog.darrenjrobinson.com/what-does-your-azure-ad-fido2-passwordless-credential-look-like/
View Get AAD FIDO2 Token Details.ps1
#Install-Module MSAL.PS
Import-Module MSAL.PS
$resource = "https://graph.windows.net" # AzureAD Graph
$apiVersion = "api-version=1.6-internal" # Internal API
$scope = "user_impersonation" # Delegated User Impersonation
$clientID = "1b730954-1685-4b74-9bfd-dac224a7b894" # PowerShell
$tenantID = "yourcompanyAADName.com" # AAD
$myUPN = "useruserUPN@yourcompanyAADName.com" # User UPN
@darrenjrobinson
darrenjrobinson / Interactive MSAL AAD Delegated AuthN.py
Last active July 27, 2021 21:02
Interactive Authentication to Microsoft Graph using MSAL with Python and Delegated Permissions. See associated blogpost https://blog.darrenjrobinson.com/interactive-authentication-to-microsoft-graph-using-msal-with-python-and-delegated-permissions/
View Interactive MSAL AAD Delegated AuthN.py
import msal
import jwt
import json
import sys
import requests
from datetime import datetime
from msal_extensions import *
# Microsoft Azure PowerShell Client ID
clientID = '1950a258-227b-4e31-a9cf-717495945fc2'