Howdy- I am working on a script that generates a report and I have to schedule to run weekly. I got the below code working, but I am not sure how to filter so I don't retrieve accounts that have certain characters in their 'samaccountname', 'cn', or 'displayname', something such as the "_"
Then others have words I need to exclude, a basic example would be systemmailbox accounts.
I also need to exclude certain OUs. I tested some of the filters and I am just not getting the right.
Then I keep getting confused/stuck on how to take what I retrieve and either email it in the body of an email as HTML (which I know is hard as it has to be formatted - but is there an easy method to auto-format?), but even emailing a CSV I am getting stuck on. If I could take this data and format it to output in excel that would be best, but if that's a big headache and I've read it's not easy and it can be troublesome, a CSV is fine. I have read the documentation on PS 4 and using the send-mailmessage, but I am just not doing something.
Get-ADUser -Filter * -SearchBase "dc=CalifDOMC001" | select DisplayName, SamAccountName, Enabled, LastLogonTimeStamp, EmployeeType, EmployeeID, useraccountcontrol, whencreated | export-csv S:\Scripts\InProg\AD_UserPreort.csv -NoTypeInformation