User Access Review
This script identifies users who have not logged in within a specified number of days (e.g., 90 days).
# Define the inactivity threshold (in days)
$inactivityThreshold = 90
$inactiveDate = (Get-Date).AddDays(-$inactivityThreshold)
# Get inactive users
$inactiveUsers = Get-ADUser -Filter {LastLogonDate -lt $inactiveDate} -Properties LastLogonDate
# Display the inactive users
foreach ($user in $inactiveUsers) {
Write-Output "User: $($user.SamAccountName), Last Logon: $($user.LastLogonDate)"
}
• Change $inactivityThreshold to set a different number of inactivity days.
Last updated