Report Help - exclude certain OUs and Accounts

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt McNabb Matt McNabb 1 year, 8 months ago.

  • Author
    Posts
  • #23694
    Profile photo of Jake Sully
    Jake Sully
    Participant

    Hi

    I am working on a report that has to be emailed out on a schedule. It has to contain all user accounts aside from accounts that exist in OUs that I have a list of and then accounts that have something like "_" in the samaccountname or displayname. I have more items that I have to filter, such as "smtp" if it exists in the displayname or samaccountname.

    I came up with the code below, can anyone help me get further? This also has to be exported in Excel if possible, otherwise csv is fine.

    Get-ADUser -Filter * -SearchBase "dc=CalifDOMC001" | select DisplayName, SamAccountName, Enabled, LastLogonTimeStamp, EmployeeType, EmployeeID, useraccountcontrol, whencreated | export-csv S:\Scripts\InProg\AD_UserPreort.csv -NoTypeInformation

    I keep getting just stuck on how to take what I pull and format it, then send it out as an email either in the message body, which for some reports I would do as HTML, but for this I would just send the attachment. I know I need to email the file, but how do I add the part to send the email?

  • #23697
    Profile photo of Matt McNabb
    Matt McNabb
    Participant

    You can convert either your AD Users or the csv to HTML easily:

    Import-Csv -Path   | ConvertTo-Html -Fragment

    Or you can just attach your csv file to an email:

    Send-MailMessage -Attachments  -To ...

You must be logged in to reply to this topic.