Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Variables
- $DaysInactive = 91
- $time = (Get-Date).Adddays(-($DaysInactive))
- $SearchBase = "OU=Users,OU=Site,DC=Domain,DC=Local"
- #Finds users defined in Searchbase that are enabled and the last log on was more than the $DaysInactive variable.
- Get-ADUser -SearchBase $SearchBase -Filter {LastLogonTimeStamp -lt $time -and Enabled -eq $true -and PasswordNeverExpires -eq $false} -Properties LastLogonTimeStamp |
- #Sets the User account to Disabled
- Set-ADuser -Enabled $false
Add Comment
Please, Sign In to add comment