ceturtdiena, 2013. gada 14. marts

Powershell script ps1 to show inactive computer accounts in AD Active Directory


Today I needed a script to show inactive computers in Active Directory 2008, I found PowerShell script, but it shows active users so I changed filter from gt- greater that to lt- less than.


Import-Module ActiveDirectory

$today = Get-Date

$cutoffdate = $today.AddDays(-60)


Get-ADComputer  -Properties * -Filter {modifyTimeStamp -lt $cutoffdate} `
| Select Name,OperatingSystem,modifyTimeStamp,CanonicalName | Export-Csv C:\Users\Admgiors\Desktop\ActiveComputers.csv



Sory to say Anand  was wrong I dont know what MS people smoke but LastLoginDate shows First Login time.
Modified means computer password was changed. Computer account password expires in  2 months.

5 komentāri:

  1. Awesome, it's very good script to view inactive computers in Active Directory. I found good information from http://www.lepide.com/active-directory-cleaner/ which helps to find out old computer account on windows server and remove inactive accounts that have been inactive within the 180 number of days. It generates comprehensive report which are based on your requirement like delete, disable, enable or move these accounts.

    AtbildētDzēst
  2. Hi, Im receiving an error with your script can I share that with you?

    AtbildētDzēst
  3. Please find the screenshoot below

    http://static.spiceworks.com/shared/post/0007/7538/screenshoot.png

    please send me an email to minoru_007@hotmail.com if you can provide me an answer

    AtbildētDzēst
  4. Kevin, in example there are script, copy it and save in file with extension like Inactive.ps or you need to run it in Active Directory PS environment.

    AtbildētDzēst
  5. Great, thanks for sharing the helpful command to get the list of active directory user and last log on time. I found a utility from http://www.esystool.com/cleanup-active-directory-with-powershell/ which provide automate facilitate to get the list which are based on active directory user and last log on details of accounts and easily mange the inactive user accounts.

    AtbildētDzēst