Files
wendeIT-scripting/Active-Directory/exportDeviceswithlastlogon.ps1
marco a59992bae8 add
add script
2026-11-25 08:05:18 +01:00

15 lines
700 B
PowerShell

$exportPath = "C:\Temp\ADClients_LastLogon.csv"
Get-ADComputer -Filter * -Properties LastLogonDate, OperatingSystem, DistinguishedName |
Select-Object Name,
OperatingSystem,
@{Name="LastLogonDate";Expression={$_.LastLogonDate}},
@{Name="DaysInactive";Expression={
if ($_.LastLogonDate) { (New-TimeSpan -Start $_.LastLogonDate -End (Get-Date)).Days }
else { "Nie angemeldet" }
}},
DistinguishedName |
Sort-Object LastLogonDate |
Export-Csv -Path $exportPath -NoTypeInformation -Encoding UTF8 -Delimiter ";"
Write-Host "Export abgeschlossen: $exportPath"