Skip to content

Instantly share code, notes, and snippets.

View caseywatson's full-sized avatar
🌳
Using my OC(d) to turn big mental trees into perfect toothpicks.

Casey Watson ☁️ caseywatson

🌳
Using my OC(d) to turn big mental trees into perfect toothpicks.
View GitHub Profile
@caseywatson
caseywatson / shut_em_down.sh1
Created March 31, 2025 22:27
Use this script to shut down all virtual machines in your Azure subscription. Careful with this one!
#!/bin/bash
# Careful with this one!
# It shuts down all virtual machines in the given subscription.
# Run it like this:
# `shut_em_down.sh1 "217991d5-5d31-4f41-9455-b1f871e610b6"` # Example subscription ID
SUBSCRIPTION_ID=$1
@caseywatson
caseywatson / Measure-VMWorkloadZonalResiliency.ps1
Last active October 11, 2024 18:09
Workload-aware Azure Availability Zone VM analysis
param(
[Parameter(Mandatory = $true)]
[string]$SubscriptionId,
[ValidateRange(2, 3)]
[int]$MinZones = 2,
[string]$ByTag,
[string]$ByNameRegexPattern,
[string]$ByKQL,
@caseywatson
caseywatson / magic_zonal_redundancy_query.kql
Created March 21, 2024 16:51
Groups VMs based on VM name using the beginning letters to the first digit to determine if vmGroup is spread across two or more availability zones. For output, it includes the tag, Application Name.
resources
| where type =~ 'microsoft.compute/virtualmachines'
| project vmId = id, vmName = name, vmZone = tostring(zones[0]), vmGroup = trim_end('\\d+$', name), appName = tags['Application Name'], location
| summarize vmCount = count(), zoneCount = dcountif(vmZone, isnotempty(vmZone)) by vmGroup
| where zoneCount < min_of(vmCount, 2)
| join kind=inner(
resources
| where type=~ 'microsoft.compute/virtualmachines'
| project vmId = id, vmName = name, vmZone = tostring(zones[0]), vmGroup = trim_end('\\d+$', name), appName = tags['Application Name'], location) on vmGroup
| project vmGroup, vmName, location, vmZone, vmId, appName
@caseywatson
caseywatson / check-capacity.ps1
Created March 15, 2024 19:44
Check Azure resource quotas
Param(
[switch]$Help,
[int]$WarningLevelPct = 70,
$SubscriptionId,
$ResourceProvider,
$QuotaApiToken
)
if ($Debug.IsPresent) {
$DebugPreference = "Continue"
@caseywatson
caseywatson / move_vms.ps1
Last active January 5, 2024 21:28
PS script for moving Azure VMs into availability zones
param (
[string]$subscriptionId = "",
[string]$bootDiagnosticsResourceGroup = "",
[string]$bootDiagnosticsStorageAccountName = "",
[string]$vmssId = "",
[switch]$keep,
[Parameter(Mandatory = $true)][string]$resourceGroup,
[Parameter(Mandatory = $true)][string]$vmName,
[Parameter(Mandatory = $true)][Int32]$zone
)
@caseywatson
caseywatson / get_functions_envs.sh
Last active February 21, 2023 15:46
Gets functionapp settings as an environment variable JSON object
#!/bin/bash
app_name=$1
resource_group=$2
settings=$(az functionapp config appsettings list \
--resource-group "$resource_group" \
--name "$app_name")
if [[ $? == 0 ]]; then # az command succeeded
@caseywatson
caseywatson / delete-my-aad-apps.sh
Last active May 30, 2022 16:18
Simple script for quickly and safely deleting AAD app registrations that you own.
#!/bin/bash -e
delete_aad_app() {
az ad app delete --id "$1"
echo "AAD app [$1] deleted."
}
usage() {
echo "Usage: $0 [-y]"
}
@caseywatson
caseywatson / WriteToAppendBlob.csx
Last active December 3, 2018 19:08
Write to Append Blob from Azure Function for Logic App Integration
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System.Configuration;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
@caseywatson
caseywatson / WriteToAppendBlob.csx
Created December 3, 2018 15:57
Write to Append Blob from Azure Function for Logic App Integration
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System.Configuration;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
@caseywatson
caseywatson / DictionaryElementAtOrDefault.cs
Created October 14, 2016 15:56
ElementAtOrDefault for Dictionaries
using System;
using System.Collections.Generic;
namespace Foo
{
public static class DictionaryExtensions
{
public static TValue ElementAtOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
{
if (dictionary == null)