Skip to content

Instantly share code, notes, and snippets.

View darrenjrobinson's full-sized avatar

Darren Robinson darrenjrobinson

View GitHub Profile
# 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/
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/
# 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-AzureADAuthenticationMethods.ps1
Last active November 1, 2021 18:51
PowerShell script to retrieve Azure AD Users Authentication Methods and add them as additional attributes on the User Object. Associated Blogpost https://blog.darrenjrobinson.com/reporting-on-users-azure-ad-authentication-methods-using-microsoft-graph-and-powershell/
Function AuthN {
<#
.SYNOPSIS
Authenticate to Azure AD and receieve Access and Refresh Tokens.
.DESCRIPTION
Authenticate to Azure AD and receieve Access and Refresh Tokens.
.PARAMETER tenantID
(required) Azure AD TenantID.
@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/
#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 / Remove Powershell ISE AddOn.ps1
Created October 11, 2016 23:07
Remove Powershell ISE Vertical AddOn Tools
# list ISE Vertical AddOn Tools
$psISE.CurrentPowerShellTab.VerticalAddOnTools
# Add on name from the list retreived above
$addOnName = 'PowerGist'
# Check you've spelled it right and remove
$exists = $psISE.CurrentPowerShellTab.VerticalAddOnTools | where { $_.Name -eq $addOnName }
if ($exists) {
$psISE.CurrentPowerShellTab.VerticalAddOnTools.Remove($exists)
@darrenjrobinson
darrenjrobinson / TestMIMADMAPorts.ps1
Last active September 9, 2021 14:10
Test Port Connectivity required for FIM/MIM Active Directory Management Agent. Associated blogpost https://blog.darrenjrobinson.com/diagnosing-fimmim-kerberos-no-logon-server-error-on-an-active-directory-management-agent/
# Insert Test-Port Function here from https://gallery.technet.microsoft.com/scriptcenter/97119ed6-6fb2-446d-98d8-32d823867131
# UDP Ports to probe
$udpports = @()
$udpports += "464" #Kerberos
$udpports += "3268" #GC
$udpports += "3269" #GC
# TCP Ports to probe
$ports = @()
@darrenjrobinson
darrenjrobinson / GetStaleAADGuestAccounts.ps1
Last active September 8, 2021 13:35
Get all AAD B2B Guest Accounts which haven't signed in, in the last XX Days, or haven't accepted a B2B Guest Invitation in last XX Days. Associated Blogpost https://blog.darrenjrobinson.com/finding-stale-azure-ad-b2b-guest-accounts-based-on-lastsignindatetime
Function AuthN {
<#
.SYNOPSIS
Authenticate to Azure AD and receieve Access and Refresh Tokens.
.DESCRIPTION
Authenticate to Azure AD and receieve Access and Refresh Tokens.
.PARAMETER tenantID
(required) Azure AD TenantID.
@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/
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'
@darrenjrobinson
darrenjrobinson / Convert Speech to Text.ps1
Last active July 23, 2021 16:55
Convert Speech to Text with PowerShell and Azure Cognitive Services STT
# Audio Phrase
$audiofile = Get-ChildItem "C:\temp\speech2convert.wav"
# Read audio into byte array
$audioBytes = [System.IO.File]::ReadAllBytes($audiofile)
# API Key
$key1 = "your api key"
# Conversion URI
$conversionURI = "https://speech.platform.bing.com/speech/recognition/interactive/cognitiveservices/v1?language=en-us&format=detailed"
# Conversion Headers
$Headers = @{