Skip to content

Instantly share code, notes, and snippets.

View santisq's full-sized avatar

Santiago Squarzon santisq

View GitHub Profile
class JwtAssertion {
[System.Security.Cryptography.X509Certificates.X509Certificate2] $Certificate
hidden [System.Text.Encoding] $encoding = [System.Text.Encoding]::UTF8
hidden [hashtable] $claims = @{
# exp: 5-10 minutes after nbf at most
exp = [System.DateTimeOffset]::UtcNow.AddMinutes(5).ToUnixTimeSeconds()
# jti: a GUID, unique identifier for the request
jti = [guid]::NewGuid().ToString()
$stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes(@'
[
{
"DomainName": "example1.com",
"DomainNetBIOSName": "EXAMPLE1",
"IDRanges": [
{ "RangeStart": 2000, "RangeEnd": 2999, "Attribute": "uidNumber", "AccountType": "Computer" },
{ "RangeStart": 3000, "RangeEnd": 3999, "Attribute": "uidNumber", "AccountType": "MSA" },
{ "RangeStart": 4000, "RangeEnd": 4999, "Attribute": "gidNumber", "AccountType": "Group" },
{ "RangeStart": 5000, "RangeEnd": 5999, "Attribute": "uidNumber", "AccountType": "AdmAccount", "IDGeneration": { "Type": "Calculation", "RefDomain": null } },
@santisq
santisq / managementGroupReport.ps1
Last active March 12, 2024 18:47
Script to report on Tenant Management Groups using Resource Manager API, KQL and PowerShell
$subIdContext = @{
Stage = 'xxxxx-xxxxx-xxxxx-xxxx'
Prod = 'xxxxx-xxxxx-xxxxx-xxxx'
}
if ($connected.Count -ne 2) {
$connected = @(
Connect-AzAccount -Subscription $subIdContext['Prod'] -SkipContextPopulation
Connect-MgGraph
)
@santisq
santisq / notsoprivate.ps1
Created January 27, 2024 05:59
not so private powershell
$private:hash = @{ foo = 'bar' }
& {
$type = $ExecutionContext.SessionState.PSVariable.GetType()
$method = $type.GetMember('GetValueAtScope', [System.Reflection.BindingFlags] 'Instance, NonPublic')
$method.Invoke($ExecutionContext.SessionState.PSVariable, ('hash', 'global'))['foo'] = 'nope'
}
$private:hash
@santisq
santisq / subscriptionReport.ps1
Last active January 30, 2024 16:51
Script to report on Tenant Subscriptions using Resource Manager API, KQL and PowerShell
Connect-AzAccount -Subscription $subIdContext['Prod']
Connect-MgGraph
class Identity {
[string] $Id
[string] $DisplayName
[string] $Type
Identity([hashtable] $identity) {
$this.Id = $identity['id']
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$MainForm = New-Object System.Windows.Forms.Form
$MainForm.Width = 420
$MainForm.Height = 200
$MainForm.FormBorderStyle = "Fixed3d"
$MainForm.MaximizeBox = $false
$MainForm.StartPosition = "CenterScreen"
@santisq
santisq / formstuff.ps1
Created November 6, 2023 20:38
winform with `.DownloadFileAsync` and progress bar
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = [System.Windows.Forms.Form]@{
Size = '500, 150'
FormBorderStyle = 'Fixed3d'
}
$btn = [System.Windows.Forms.Button]@{
Name = 'MyButton'

Setup new Azure Data Explorer Table from MyAADLogs

This document details the steps needed to create a new Azure Data Explorer table for ingested logs from Azure Active Directory.

All ingested logs from AAD are written to a table in ADX named MyAADLogs, this table is overwritten over and over thus the need to create a parsing function which is used to filter the new ingested logs by their category and construct new records out of it to then write them to their corresponding tables.

Query MyAADLogs Table

First step is to query the MyAADLogs table filtering by the record.category property and expanding those properties of interest from each record. We can query the same logs using Log Analytics for comparison. For example, for NonInteractiveUserSignInLogs:

@santisq
santisq / BinarySearch.perf.ps1
Last active October 10, 2023 18:22
performance test for List<T> and Array BinarySearch Method
[System.Collections.Generic.List[int]] $list = 0..10mb
[int[]] $arr = $list.ToArray()
$ran = 0..100 | ForEach-Object { Get-Random -Maximum 15mb }
$tests = @{
'Array.BinarySearch' = { [array]::BinarySearch($args[0], $args[1]) }
'Array.IndexOf' = { $args[0].IndexOf($args[1]) }
'List.BinarySearch' = { $args[0].BinarySearch($args[1]) }
'List.IndexOf' = { $args[0].IndexOf($args[1]) }
@santisq
santisq / IModuleAssemblyCleanupTest.ps1
Created September 13, 2023 01:14
how to perform OnRemove in C#
Add-Type '
using System;
using System.Management.Automation;
namespace IModuleAssemblyCleanupTest;
public class Testing : IModuleAssemblyCleanup
{
public void OnRemove(PSModuleInfo psModuleInfo) =>
Console.WriteLine("Hello!");