I am trying to get a powershell script together to go through all users in our domain and find if they have a SIDhistory located in the SIDhistory attribute or not. I then need to export this list of users to a csv as i will need to delete all the accounts without a SIDhistory. I'm still learning powershell but this is what I have so far to find individual user's sidhistory. ( export CSV portion isn't working correctly )
dsquery * -Filter "(samaccountname=USERID)" -Attr samAccountName ObjectSID sidHistory | export-csv -path C:\Desktop\insertcsv.csv -notypeinformation
Thank you any help you can provide, I really appreciate it.
tl;dr - I need to pull all users with an empty SIDhistory attribute to a csv
get-aduser -filter {!(SIDhistory = *)} -prop ObjectSID,sidHistory|Select SamAccountName,ObjectSID,sidHistory|ExportCsv $env:USERPROFILE\Desktop\NoSIDHistory.csv -notype
– TheMadTechnician