Skip to content

Instantly share code, notes, and snippets.

View santisq's full-sized avatar

Santiago Squarzon santisq

View GitHub Profile
@santisq
santisq / aes-cbc.cs
Last active March 27, 2026 22:36
AES encrypt / decrypt strings
using System;
using System.IO;
using System.Management.Automation;
using System.Security.Cryptography;
using System.Text;
[Cmdlet(VerbsDiagnostic.Test, "Encrypt")]
public sealed class EncryptAes : PSCmdlet
{
[Parameter(Mandatory = true, Position = 0)]
@santisq
santisq / CustomVariableProvider.cs
Last active March 20, 2026 20:01
A custom PowerShell variable provider implementation that evaluates script blocks on inspection
// Source - https://stackoverflow.com/a/79911456
// Posted by Santiago Squarzon, modified by community. See post 'Timeline' for change history
// Retrieved 2026-03-20, License - CC BY-SA 4.0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Provider;
# Requires module ClassExplorer
$method = [System.Management.Automation.LanguagePrimitives] | fime -f FigureConversion -ParameterCount 3
# Rank: NullToValue
$flag = $null
$converter = $method.Invoke($null, @($null, [int], $flag))
$converter.Invoke($null, [int], $true, $null, [cultureinfo]::InvariantCulture, $null)
# Rank: NullToRef
$flag = $null
@santisq
santisq / keepalive.cs
Last active February 27, 2026 22:54
SetThreadExecutionState... keeps your powershell script running without going to sleep
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
public static class Native
{
private static EXECUTION_STATE? s_prevState;
private const uint INPUT_KEYBOARD = 1;
private const uint KEYEVENTF_KEYUP = 0x0002;
@santisq
santisq / .gitignore
Last active January 9, 2026 23:33
Adapted `Import-Csv` source to output `IEnumerable<T>`
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
benchmarks/
BenchmarkDotNet.Artifacts/
tools/dotnet
# User-specific files
*.suo
*.user
@santisq
santisq / InvokeRetry.ps1
Created October 20, 2025 12:33
simple retry function
function Invoke-Retry {
[Alias('retry')]
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[scriptblock] $Scriptblock,
[Parameter()]
[scriptblock] $RetryHandler,
function Get-EffectiveAccess {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidatePattern('(?:(CN=([^,]*)),)?(?:((?:(?:CN|OU)=[^,]+,?)+),)?((?:DC=[^,]+,?)+)$')]
[alias('DistinguishedName')]
[string] $Identity,
[parameter()]
[alias('Domain')]
@santisq
santisq / GetComputerInfo.cs
Last active January 17, 2026 14:31
Get-ComputerInfo with PowerShell SDK
using System;
using System.Collections;
using System.Linq;
using System.Management.Automation;
using System.Reflection;
using System.Text;
using Microsoft.PowerShell.Commands;
using PowerShell ps = PowerShell.Create().AddCommand("Get-ComputerInfo");
ComputerInfo info = ps.Invoke<ComputerInfo>()[0];

storageAccountKeyRotation.ps1

This automation finds and rotates Keys that are created after specified $dayLimit.
Additionally, finds and updates the Environment Variables (if any) of Function Apps associated with the rotated Key.

functionAppConnectionStrings.ps1

This automation finds and updates any Environment Variable having a connection string that does not match with their associated Storage Account connection string.

Required Modules

static unsafe void ToTitleCase(string input)
{
if (input.Length == 0)
{
return;
}
fixed (char* chars = input)
{
bool startOrNotLetter = true;