Skip to content

Instantly share code, notes, and snippets.

@maskati
maskati / #azure-change-analysis.md
Last active April 11, 2024 10:19
Azure Change Analysis query including change actor details

Azure Change Analysis enhances the visibility of changes made to Azure resources. It does this by tracking these changes at the subscription level and recording them in the Azure Resource Graph's resourceschanges table.

As of March 2024, change tracking now also includes detailed information about the principal that initiated the change, the client type (e.g. Azure Portal, Azure CLI, ARM template), and the operation which resulted in the change (e.g. Microsoft.Web/sites/write). This enhancement means you no longer need to consult Azure activity logs separately to understand who initiated a change and what action they performed. Everything is conveniently available within th

@maskati
maskati / #azure-servicetags-ipnetwork.md
Created November 28, 2023 05:59
Check which Azure service tag network prefixes contain a specific IP address

Run with PowerShell 7.4 or later based on .NET 8 which includes the new IPNetwork type. Requires authenticated Azure CLI.

# e.g. ns-sb2-prod-am3-002.cloudapp.net (service bus namespace in westeurope)
$ip=[net.ipaddress]::parse("104.46.32.56")

az network list-service-tags --location westeurope | `
 convertfrom-json | `
@maskati
maskati / #my-ip-dns.md
Created September 21, 2023 08:02
Get my IP address using DNS

Windows

nslookup myip.opendns.com resolver1.opendns.com

Linux

dig +short myip.opendns.com @resolver1.opendns.com
@maskati
maskati / #emulate-managed-identity.md
Last active April 8, 2024 17:49
Emulate Azure managed identity locally
@maskati
maskati / #applicationinsights-stream-live-metrics.md
Last active August 8, 2023 13:01
Stream Application Insights live metrics to a local PowerShell grid view

This PowerShell script streams Application Insights live metric traces to your local system and displays them in a PowerShell grid view. This is useful since the Azure Portal trace viewing experience is somewhat limited.

Warning

This script uses undocumented functionality. Exercise caution when running any scripts against your infrastructure.

To use:

  1. Ensure you are logged in using Azure CLI and have selected the relevant subscription.
  2. Run the script in a PowerShell terminal (tested only with PowerShell 7.3).
  3. Select the relevant Application Insights resource from the first grid view. This lists all Application Insights resources in the Azure CL

This script retrieves published Azure location information and transforms it into GeoJSON format, with Point features indicating Azure regions and LineString features indicating links between paired regions.

$locations=az account list-locations --query "[?metadata.regionType=='Physical']"|convertfrom-json
@{type='FeatureCollection';features=$($locations|?{$_.metadata.pairedRegion.count -eq 1}|%{$r=$_;$p=$locations|?{$_.name -eq $r.metadata.pairedRegion[0].name}|select -first 1;if($null -ne $p -and -not (($r.metadata.longitude -eq 0 -and $r.metadata.latitude -eq 0) -or ($p.metadata.longitude -eq 0 -and $p.meta