All scripts
Azure AI 592

Azure AKS Cluster Inventory Report

Pulls a quick inventory of every AKS cluster in a subscription, including Kubernetes version, node pool sizes, and auto-upgrade channel, so you can spot clusters drifting toward an out of support version before Microsoft forces an upgrade window on you.

Get-AzureAksClusterInventory.ps1
<#
.SYNOPSIS
    Reports on every AKS cluster in a subscription, including Kubernetes version and node pool details.
.DESCRIPTION
    Connects to Azure, finds every AKS cluster the account can see (optionally scoped to one
    resource group), and reports the Kubernetes version, node pool sizes and counts, and
    whether auto-upgrade is configured. Useful for spotting clusters that are drifting toward
    an out of support Kubernetes version before Microsoft forces an upgrade window on you.
.PARAMETER ResourceGroupName
    Optional. Limit the report to AKS clusters in a single resource group. If omitted, every
    cluster in the current subscription is checked.
.PARAMETER ExportPath
    Optional. Path to a CSV file to export the results to, in addition to printing them.
.EXAMPLE
    .\Get-AzureAksClusterInventory.ps1
    Lists every AKS cluster in the current subscription with version and node pool details.
.EXAMPLE
    .\Get-AzureAksClusterInventory.ps1 -ResourceGroupName "prod-rg" -ExportPath "C:\reports\aks.csv"
    Reports only on clusters in prod-rg and saves the results to a CSV file.
.AUTHOR
    Shehryar Hassan
#>

[CmdletBinding()]
param(
    [string]$ResourceGroupName,
    [string]$ExportPath
)

if (-not (Get-Module -ListAvailable -Name Az.Aks)) {
    Write-Error "The Az.Aks module is required. Install it with: Install-Module Az.Aks -Scope CurrentUser"
    return
}

$context = Get-AzContext
if (-not $context) {
    Write-Host "Not connected to Azure. Connecting now..."
    Connect-AzAccount | Out-Null
}

if ($ResourceGroupName) {
    $clusters = Get-AzAksCluster -ResourceGroupName $ResourceGroupName
} else {
    $clusters = Get-AzAksCluster
}

if (-not $clusters) {
    Write-Host "No AKS clusters found."
    return
}

$results = foreach ($cluster in $clusters) {
    foreach ($pool in $cluster.AgentPoolProfiles) {
        [PSCustomObject]@{
            ClusterName        = $cluster.Name
            ResourceGroup      = $cluster.ResourceGroupName
            Location           = $cluster.Location
            KubernetesVersion  = $cluster.KubernetesVersion
            AutoUpgradeChannel = $cluster.AutoUpgradeProfileUpgradeChannel
            NodePoolName       = $pool.Name
            VmSize             = $pool.VmSize
            NodeCount          = $pool.Count
            Mode               = $pool.Mode
        }
    }
}

$results | Sort-Object ClusterName, NodePoolName | Format-Table -AutoSize

if ($ExportPath) {
    $results | Export-Csv -Path $ExportPath -NoTypeInformation
    Write-Host "Exported to $ExportPath"
}

Read it before you run it, and test in a safe tenant first.