Skip to content

Instantly share code, notes, and snippets.

@potatoqualitee
potatoqualitee / so.ps1
Last active August 22, 2024 10:15
Structured Objects in PowerShell using PSOpenAI
############# Install PSOpenAI and set your API key #############
Install-Module PSOpenAI
Import-Module PSOpenAI # only when it's first installed
$env:OPENAI_API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx'
############# Here's some markdown that'd be extracted from a PDF, however you want #############
$markdown = "# Dog Shot Record
2309 Kelley Road, Gulfport, MS, 39501
**CLINIC NAME**
Phone: 123-1234567 - Email: [email protected]
@JustinGrote
JustinGrote / Start-MSIEmulator.ps1
Last active August 29, 2024 14:53
A Managed Identity Emulator for testing Managed Identities locally. Returns a token from your currently logged in Azure PowerShell context
#requires -Module Az.Accounts
$verbosePreference = 'continue'
function ConvertFrom-JWTtoken {
<#
.NOTES
Lovingly borrowed from: https://www.michev.info/blog/post/2140/decode-jwt-access-and-id-tokens-via-powershell
#>
[cmdletbinding()]
param([Parameter(Mandatory = $true)][string]$token)
#requires -module Az.Functions
function Write-CmdletError {
param($message, $cmdlet = $PSCmdlet)
$cmdlet.ThrowTerminatingError(
[Management.Automation.ErrorRecord]::new(
$message,
'CmdletError',
'InvalidArgument',
@JustinGrote
JustinGrote / Get-MgServicePrincipalPermission.ps1
Last active November 6, 2024 10:21
Get a list of application and delegated permissions for a service principal, similar to what the Azure Portal shows
#requires -version 7 -module Microsoft.Graph.Applications
using namespace Microsoft.Graph.PowerShell.Models
using namespace System.Collections.Generic
enum MicrosoftGraphServicePrincipalType {
Application
Delegated
}
class MgServicePrincipalPermission {
@Fabaderheld
Fabaderheld / Set-AzAPIPermission.ps1
Last active July 7, 2022 18:32
Permissions Ids for Graph
Get Permissions
# MS Graph Permissions
(Get-AzAdServicePrincipal -ApplicationId 00000003-0000-0000-c000-000000000000).AppRole | Select *
(Get-AzAdServicePrincipal -ApplicationId 00000003-0000-0000-c000-000000000000).Oauth2PermissionScope | Select *
# Azure AD Graph
(Get-AzAdServicePrincipal -ApplicationId 00000002-0000-0000-c000-000000000000).AppRole | Select *
(Get-AzAdServicePrincipal -ApplicationId 00000002-0000-0000-c000-000000000000).Oauth2PermissionScope | Select *
@JustinGrote
JustinGrote / Get-ParamBlock.ps1
Created July 7, 2022 05:20
Get a hashtable of the parameters in your param block, useful for splatting.
using namespace system.collections.generic
function Get-ParamBlock ([String[]]$Name) {
[hashset[string]]$params = $PSCmdlet.MyInvocation.MyCommand.Parameters.Keys
$params.ExceptWith([string[]]([PSCmdlet]::CommonParameters + [PSCmdlet]::OptionalCommonParameters))
$result = @{}
if ($Name) {$params = $params -in $Name}
foreach ($name in $params) {
$result.$name = $PSCmdlet.GetVariableValue($name)
}
return $result
@JustinGrote
JustinGrote / Receive-Task.ps1
Last active September 21, 2022 21:05
"Await" one or more tasks in PowerShell in a cancellable manner (e.g. ctrl-c still works)
using namespace System.Threading.Tasks
using namespace System.Collections.Generic
filter Receive-Task {
#Wait on one or more tasks in a cancellable manner
[CmdletBinding()]
param(
[parameter(Mandatory, ValueFromPipeline)][Task]$Task,
#How long to wait before checking for a cancellation in milliseconds
[int]$WaitInterval = 500
)
@JustinGrote
JustinGrote / Trace-AICommand.ps1
Last active August 21, 2024 18:48
Trace-AICommand: Report the results and performance of any scriptblock to Azure Application Insights
#requires -version 7
#You can load this script with $(iwr https://tinyurl.com/TraceAICommand | iex)
using namespace Microsoft.ApplicationInsights
using namespace Microsoft.ApplicationInsights.Extensibility
using namespace Microsoft.ApplicationInsights.DataContracts
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Net
#Reference: https://docs.microsoft.com/en-us/azure/azure-monitor/app/console
@timothywarner
timothywarner / warner-bicep-2022.md
Last active May 14, 2023 11:59
Azure Bicep Quick Start by Tim Warner (@TechTrainerTim)
@BelRarr
BelRarr / list-expiring-app-registrations.ps1
Created January 10, 2022 14:27
Get the list of expired or soon-to-expire azure app registrations
$daysToExpire = 30
$SoonToBeExpiredList = @()
$AlreadyExpiredList = @()
# Connect to AzureAD
Write-Output "Connecting to AzureAD..."
$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzureAD -TenantId $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint