Report Help - exclude certain OUs and Accounts

Welcome Forums General PowerShell Q&A Report Help - exclude certain OUs and Accounts

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 11 months ago.

  • Author
  • #23694

    Points: 0
    Rank: Member


    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

    Points: 2
    Rank: Member

    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 ...

The topic ‘Report Help - exclude certain OUs and Accounts’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort