<# Azure-Kosten-Autopilot - Lese-Skript (nur lesen, keine Aenderungen) Luna group L.L.C-FZ, Dubai - https://azurekosten.lunafzai.com Version 1.0 (26.11.2026) Was es tut: Fragt mit Azure Resource Graph (Search-AzGraph, nur lesen) ungenutzte Ressourcen ab (nicht angehaengte Datentraeger, alte Snapshots, freie oeffentliche IPs, leere App-Service-Plaene, VMs) und schreibt EINE Datei "azure-inventar.json" auf Ihren PC. Was es NICHT tut: Es aendert, startet oder loescht nichts und sendet nichts an uns. Die Datei bleibt auf Ihrem PC; Sie laden sie selbst im Browser, dort wird sie lokal ausgewertet. Voraussetzungen: PowerShell 7 oder 5.1, Module Az.Accounts und Az.ResourceGraph (Install-Module Az.Accounts, Az.ResourceGraph -Scope CurrentUser), Rolle "Leser" (Reader) auf den Abonnements. Aufruf: .\azure-inventar.ps1 #> param([string]$Ausgabe = ".\azure-inventar.json") $ErrorActionPreference = "Stop" $R = [ordered]@{ format = "luna-azure-inventar"; version = 1; erstellt = (Get-Date).ToUniversalTime().ToString("o"); fehler = @() } function Abfrage($name, $kql) { Write-Host "-> $name ..." -ForegroundColor Cyan try { $alle = @(); $tok = $null do { if ($tok) { $r = Search-AzGraph -Query $kql -First 1000 -SkipToken $tok } else { $r = Search-AzGraph -Query $kql -First 1000 } $alle += @($r | ForEach-Object { $_ | Select-Object * -ExcludeProperty ResourceId }); $tok = $r.SkipToken } while ($tok) $script:R[$name] = $alle; Write-Host " $($alle.Count) gefunden" } catch { $script:R.fehler += "$($name): $($_.Exception.Message)"; Write-Host " nicht lesbar: $($_.Exception.Message)" -ForegroundColor Yellow } } if (-not (Get-AzContext)) { Connect-AzAccount | Out-Null } Abfrage "datentraegerFrei" "Resources | where type =~ 'microsoft.compute/disks' | where isempty(managedBy) and tostring(properties.diskState) =~ 'Unattached' | project id=tolower(id), sku=tostring(sku.name), gb=toint(properties.diskSizeGB), erstellt=tostring(properties.timeCreated)" Abfrage "snapshots" "Resources | where type =~ 'microsoft.compute/snapshots' | project id=tolower(id), gb=toint(properties.diskSizeGB), erstellt=tostring(properties.timeCreated)" Abfrage "ipFrei" "Resources | where type =~ 'microsoft.network/publicipaddresses' | where isnull(properties.ipConfiguration) and isnull(properties.natGateway) | project id=tolower(id), sku=tostring(sku.name)" Abfrage "planLeer" "Resources | where type =~ 'microsoft.web/serverfarms' | where toint(properties.numberOfSites) == 0 | project id=tolower(id), sku=tostring(sku.name)" Abfrage "vms" "Resources | where type =~ 'microsoft.compute/virtualmachines' | project id=tolower(id), groesse=tostring(properties.hardwareProfile.vmSize), status=tostring(properties.extended.instanceView.powerState.code), umgebung=tostring(coalesce(tags.Environment, tags.environment, tags.Umgebung, tags.env, tags.Env, '')), rg=tolower(resourceGroup)" $R | ConvertTo-Json -Depth 6 | Out-File -FilePath $Ausgabe -Encoding utf8 Write-Host ""; Write-Host "Fertig: $((Resolve-Path $Ausgabe).Path)" -ForegroundColor Green Write-Host "Laden Sie die Datei auf der Seite im Browser; sie verlaesst Ihren PC nicht." -ForegroundColor Green