# Report Help - exclude certain OUs and Accounts

**URL:** https://forums.powershell.org/t/report-help-exclude-certain-ous-and-accounts/3940
**Category:** PowerShell Help
**Created:** [March 25, 2015, 3:00pm UTC](https://forums.powershell.org/t/report-help-exclude-certain-ous-and-accounts/3940 "2015-03-25T15:00:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jake-sully2](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jake-sully2](https://forums.powershell.org/u/jake-sully2)
#### Post date: [March 25, 2015, 3:00pm UTC](https://forums.powershell.org/t/report-help-exclude-certain-ous-and-accounts/3940/1 "2015-03-25T15:00:34Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![matt-mcnabb](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-mcnabb](https://forums.powershell.org/u/matt-mcnabb)
#### Post date: [March 25, 2015, 11:12pm UTC](https://forums.powershell.org/t/report-help-exclude-certain-ous-and-accounts/3940/2 "2015-03-25T23:12:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/report-help-exclude-certain-ous-and-accounts/3940/3 "2024-05-16T20:45:34Z")

</div>


