Skip to content

Instantly share code, notes, and snippets.

View mattbalzan's full-sized avatar
🏠
Working from home

mattGPT mattbalzan

🏠
Working from home
View GitHub Profile
@mattbalzan
mattbalzan / EncodeXMLtoBase64.ps1
Created January 24, 2025 16:14
Encode XML to Base64
$xml = gc C:\appassoc.xml
$enc = [System.Text.Encoding]::Unicode.GetBytes($xml)
$encXML = [Convert]::ToBase64String($enc)
$encXML
@mattbalzan
mattbalzan / mattGPT_PSISE_editor_AddOn.ps1
Last active January 24, 2025 16:00
PS ISE Editor Custom Add-On
$action1 = {
$psise.CurrentFile.Editor.InsertText("# --[ ]")
# Get the current cursor position
$currentLine = $psISE.CurrentFile.Editor.CaretLine
$currentColumn = $psISE.CurrentFile.Editor.CaretColumn
# Calculate the new column position
$newColumn = [math]::Max(1, $currentColumn - 2)
@mattbalzan
mattbalzan / SetAzureMSI-GraphPermissions.ps1
Created January 22, 2025 17:20
Set Azure MSI Graph permissions
$TenantID = "<tenantID>"
$ManagedIdentity = "<MSI name>"
$Permissions = @("DeviceManagementManagedDevices.Read.All", "DeviceManagementManagedDevices.ReadWrite.All", "AuditLog.Read.All", "User.Read.All")
$GraphAppId = "00000003-0000-0000-c000-000000000000"
Connect-AzureAD -TenantId $TenantID
$ManagedIdentityServicePrincipal = (Get-AzureADServicePrincipal -Filter "displayName eq '$ManagedIdentity'")
$GraphServicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq '$GraphAppId'"
foreach ($Permission in $Permissions)
@mattbalzan
mattbalzan / Add New Snippet.ps1
Created January 6, 2025 10:58
Add New Snippet
# --[ Add New Snippet ]
# --[ Matt Balzan | mattGPT.co.uk ]
$text = @"
<paste your PS code here>
"@
New-IseSnippet -Title "<name of snippet>" -Description "<description of snippet>" -Author "mattGPT" -Text $text
@mattbalzan
mattbalzan / Invoke Azure Runbook Webhook.ps1
Last active January 6, 2025 11:01
Invoke Azure Runbook Webhook
# --[ Invoke Azure Runbook Webhook ]
# --[ Matt Balzan | mattGPT.co.uk ]
# --[ Set Variables ]
$webhookURI = "https:\\<webhook-URI>"
# --[ Parameters for Webhook ]
$params = @{
param1 = "deviceName"
param2 = "userName"
@mattbalzan
mattbalzan / Log Function.ps1
Created January 6, 2025 10:55
Simple Log Function
# --[ Log Function ]
# --[ Matt Balzan | mattGPT.co.uk ]
# --[ Set vars ]
$customer = "mattGPT"
$feature = "Stuff"
$logPath = "C:\ProgramData\$customer\$feature"
$logfile = "$logPath\$feature.log"
if(!(Test-Path $logPath)){ New-Item -Path $logPath -ItemType Directory -Force }
@mattbalzan
mattbalzan / Windows Toast Message.ps1
Created January 6, 2025 10:52
Windows Toast Message
# --[ Windows Toast Message ]
# --[ Matt Balzan | mattGPT.co.uk ]
function Toast($Title,$msgText){
# Main script
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
@mattbalzan
mattbalzan / Decode base64 to file.ps1
Last active January 6, 2025 11:00
Decode base64 to file
# --[ Decode base64 to file ]
# --[ Matt Balzan | mattGPT.co.uk ]
$b64 = "paste here all the base64 text"
$filename = "path\to\imagefile"
$bytes = [Convert]::FromBase64String($b64)
[IO.File]::WriteAllBytes($filename, $bytes)
@mattbalzan
mattbalzan / Encode image to base64.ps1
Last active January 6, 2025 11:02
Encode image to base64
# --[ Encode image to base64 ]
# --[ Matt Balzan | mattGPT.co.uk ]
$path = "path\to\image\file.jpg"
[convert]::ToBase64String((Get-Content $path -Encoding byte)) >> "path\to\save\base64\text\to.txt"
@mattbalzan
mattbalzan / URI encoder.ps1
Last active January 6, 2025 10:48
URI encoder
# --[ Encode URI to base64 ]
# --[ Matt Balzan | mattGPT.co.uk ]
$url = '<your_URI>'
$enc = [System.Text.Encoding]::Unicode.GetBytes($url)
$encURL = [Convert]::ToBase64String($enc)
$encURL