none
Clean up old service accounts RRS feed

  • Question

  • I have five domain controller that i need to powershell against, essentially i need to clean up service accounts (user accounts) to determine what can be safely deleted, and query the following into a CSV:


    CN,samaccountname,displayName,lastLogon,lastLogonTimestamp,mail or target address


    My service accounts live in the following OU's:


    OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=POC,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=Sharepoint Dev,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=Sharepoint Prd,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=EPC Sandbox,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=IS OnCall,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=EPC Dev,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=EPC Prd,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=MobileIron Accounts,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=DEV,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com
    OU=Azure Service Accounts,OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com






    So far i have this but it isn't reporting on "lastlogon", or "displayname". Really need some help please!


    Get-ADUser -Filter * -SearchBase "OU=Service Accounts,OU=SSG,DC=ssg,DC=domainname,DC=com" -ResultPageSize 0 -Prop CN,samaccountname,displayName,lastLogon,lastLogonTimestamp | Export-CSV C:\SSGServiceAccounts\Users.csv -NoType 
    • Moved by Bill_Stewart Thursday, December 20, 2018 9:16 PM This is not "scripts on demand"
    Tuesday, October 16, 2018 3:24 PM

All replies