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 / 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)
@caseywatson
caseywatson / OrderBySelfExtensions.cs
Created September 29, 2016 20:20
For when you just want to OrderBy yourself...
using System.Collections.Generic;
using System.Linq;
namespace Mantle.Extensions
{
public static class EnumerableExtensions
{
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source)
{
if (source == null)
@caseywatson
caseywatson / FunctionalStringSplitExtension.cs
Created August 26, 2016 14:36
Similar to C# string.Split but splits on a condition, not a character array. Great for quick and easy string tokenization.
using System;
using System.Collections.Generic;
using System.Text;
namespace Extensions
{
public static class FunctionalStringSplitExtension
{
public static string[] Split(this string source, Func<char, bool> splitOn)
{