# Importiere das Active Directory Modul Import-Module ActiveDirectory # Definiere das heutige Datum $Today = Get-Date # Definiere den Schwellenwert (in diesem Fall 30 Tage) $Threshold = $Today.AddDays(-30) # Abfrage von Benutzern, die sich seit mehr als 30 Tagen nicht angemeldet haben $InactiveUsers = Get-ADUser -Filter {LastLogonDate -lt $Threshold -and Enabled -eq $true} -Property DisplayName, SamAccountName, LastLogonDate, Enabled | Select-Object DisplayName, SamAccountName, @{Name='LastLogonDate';Expression={[datetime]::FromFileTime($_.LastLogonDate)}}, Enabled # Definiere den Pfad zur Desktop TXT-Datei $DesktopPath = [Environment]::GetFolderPath('Desktop') $TxtFilePath = Join-Path -Path $DesktopPath -ChildPath "InactiveUsers.txt" # Formatierung der Ausgabe $Output = $InactiveUsers | Format-Table -Property DisplayName, SamAccountName, LastLogonDate -AutoSize | Out-String # Speichern der Informationen in die TXT-Datei $Output | Out-File -FilePath $TxtFilePath -Encoding UTF8 Write-Host "Die TXT-Datei wurde unter $TxtFilePath erstellt."