I don’t have my server available to validate the exact syntax, so consider this pseudo code for some pointers.
#Get all accounts apart from excluded ones
$excludedAccounts = @(‘my’,‘list’,‘of’,‘excluded’,‘accounts’)
$nonExcludedAccounts = Get-ADUser -Filter * -Property * | Where SamAccountName -notin $excludedAccounts
#Apart from OUs that begin with…
In order to check the OU where the user is located, I think you’re going to have to access the DistinguishedName or CanonicalName attributes, and then parse them to identify the OU (the CN is the first item in it, not the OU). The AD cmdlets are not as pipeline friendly as some of the other cmdlets, so you can’t combine Get-ADUser with Get-ADOrganizationalUnit. Alternatively, you could reverse the order wherby you use Get-OrganizationalUnit first, apply a filter, and then from those results, use Get-ADUser with a SearchBase attribute of the DN from the each item in the collection returned by Get-ADOrganizationalUnit.
#Get some properties
$userAttributes = $finalUserList | Select Property1,Property2
#Export to CSV
Use Export-CSV with $userAttributes
Use Send-MailMessage with the file details.