Skip to content

Instantly share code, notes, and snippets.

View darrenjrobinson's full-sized avatar

Darren Robinson darrenjrobinson

View GitHub Profile
View Import.ps1
param (
$Username,
$Password,
$OperationType,
[bool] $usepagedimport,
$pagesize
)
#Needs reference to .NET assembly used in the script.
View Get Azure AD Authentication Methods Summary Reports.ps1
Function DelegatedAuthN {
<#
.SYNOPSIS
Authenticate to Azure AD (using Delegated Auth) and receieve Access and Refresh Tokens.
.DESCRIPTION
Authenticate to Azure AD (using Delegated Auth) and receieve Access and Refresh Tokens.
.PARAMETER tenantID
@darrenjrobinson
darrenjrobinson / Get-Unifi-Details.ps1
Last active June 30, 2023 08:28
PowerShell Script to get Ubiquiti Unifi Sites, Devices and Active Clients. Associated blogpost https://blog.darrenjrobinson.com/accessing-your-ubiquiti-unifi-network-configuration-with-powershell/
View Get-Unifi-Details.ps1
# Unifi Controller Login Base URI
$uController = 'yourControllerIP' # e.g 'https://192.168.1.2:8443'
# Identifier of the site in UniFi. Set to default for the default site
$uSiteID = "default"
$uUsername = 'adminuser' # yourAdmin UserID
$uPassword = 'yourPassword' # yourAdmin User Password
$uAuthBody = @{"username" = $uUsername; "password" = $uPassword }
$uHeaders = @{"Content-Type" = "application/json" }
@darrenjrobinson
darrenjrobinson / Microsoft Graph using MSAL with Python and Delegated Permissions.py
Last active May 1, 2023 13:59
Microsoft Graph using MSAL with Python and Delegated Permissions using a persistent local MSAL Cache. Associated Blogpost https://blog.darrenjrobinson.com/microsoft-graph-using-msal-with-python-and-delegated-permissions/
View Microsoft Graph using MSAL with Python and Delegated Permissions.py
import msal
import jwt
import json
import sys
import requests
from datetime import datetime
from msal_extensions import *
graphURI = 'https://graph.microsoft.com'
tenantID = 'yourTenantID'
@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
@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
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
View PS2GraphAPI.ps1
# The resource URI
$resource = "https://graph.microsoft.com"
# Your Client ID and Client Secret obainted when registering your WebApp
$clientid = "726ec7c7-ff9e-4c28-b864-************"
$clientSecret = "KjYwt9tIf13kdBub7vaBJv4********************="
$redirectUri = "https://localhost:8001"
# UrlEncode the ClientID and ClientSecret and URL's for special characters
$clientIDEncoded = [System.Web.HttpUtility]::UrlEncode($clientid)
@darrenjrobinson
darrenjrobinson / ExcuseGenerator.ps1
Last active March 7, 2023 16:53
Bastard Operator from Hell Excuse Generator
View ExcuseGenerator.ps1
function BOFHExcuse {
# BOFH Excuse Generator
$first =@("Temporary","Intermittant","Partial","Redundant","Total","Multiplexed","Inherent","Duplicated","Dual-Homed","Synchronous","Bidirectional","Serial","Asynchronous","Multiple","Replicated","Non-Replicated","Unregistered","Non-Specific","Generic","Migrated","Localised","Resignalled","Dereferenced","Nullified","Aborted","Serious","Minor","Major","Extraneous","Illegal","Insufficient","Viral","Unsupported","Outmoded","Legacy","Permanent","Invalid","Deprecated","Virtual","Unreportable","Undetermined","Undiagnosable","Unfiltered","Static","Dynamic","Delayed","Immediate","Nonfatal","Fatal","Non-Valid","Unvalidated","Non-Static","Unreplicatable","Non-Serious")
$second = @("Array","Systems","Hardware","Software","Firmware","Backplane","Logic-Subsystem","Integrity","Subsystem","Memory","Comms","Integrity","Checksum","Protocol","Parity","Bus","Timing","Synchronisation","Topology","Transmission","Reception","Stack","Framing","Code","Programming","Peripheral
View Aggregate Source without Optimization.ps1
# Your API Client ID
$clientID = 'yourClientID'
# Your API Client Secret
$clientSecret = 'yourSecret'
$Bytes = [System.Text.Encoding]::utf8.GetBytes("$($clientID):$($clientSecret)")
$encodedAuth = [Convert]::ToBase64String($Bytes)
# Your IdentityNow Tenant Name
$orgName = 'yourOrg'
# IdentityNow Admin User and PWD to connect with via oAuth
$adminUSR = [string]"yourAdminAccount".ToLower()