When starting a migration, it is best practice to clean up your active directory.
But how do you know, especially in large environments, which computer accounts are from computers that are no longer part of your domain? Most of the times, this will take some serious manual labor, which I dislike doing.
So, how can this be automated?
To find old computer accounts:
get-adcomputer -properties lastLogonDate -filter * | where { $_.lastLogonDate -lt (get-date).addmonths(-12) } | sort Name | FT Name,LastLogonDate
And to delete the old computer accounts:
get-adcomputer -properties lastLogonDate -filter * | where { $_.lastLogonDate -lt (get-date).addmonths(-12) } | Remove-ADComputer -whatif
Next up is finding and removing old user accounts which I will be posting later today ![]()

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 