Zum Inhalt
Kaffeeundcode
Skriptbibliothek
PowerShell 06.10.2026

PowerShell

Get ExpiringSecrets

124_Get-ExpiringSecrets.ps1

<#
.SYNOPSIS
    Findet ablaufende Secrets.

.DESCRIPTION
    <!-- library-status:start -->
    Prüfstatus: Ungeprüft
    Windows- und Tenant-Abnahme ausstehend; keine pauschale Produktionsfreigabe.

    <!-- library-status:end -->

    Durchsucht Apps nach Secrets, die bald ablaufen.
    Erfordert die Berechtigung 'Application.Read.All'.

.NOTES
    File Name: 124_Get-ExpiringSecrets.ps1
    Author: Mattia Cirillo
    Version: 1.0
#>

param()

Connect-MgGraph -Scopes "Application.Read.All"

$Apps = Get-MgApplication -All
foreach ($App in $Apps) {
    # PasswordCredentials contains secrets
    foreach ($Cred in $App.PasswordCredentials) {
        if ($Cred.EndDateTime -lt (Get-Date).AddDays(30)) {
            Write-Host "Ablaufendes Secret in App '$($App.DisplayName)' am $($Cred.EndDateTime)" -ForegroundColor Yellow
        }
    }
}