0
In our organization we have users who are setup to have email sent to domains outside of our organization (Mail Users). So their primary email address is different from our standard FQDN.
What I am trying to do is pull all enabled users in AD and sort the users with our primary FQDN into one last and users with anything else into another list.
I have been able to get the following to produce a single list but I cannot get it to sort it into two lists by email type.
$users = Get-ADUser -Filter {Enabled -eq $true} -SearchBase "Removed" -Properties mail, givenName, initials, sn, title, extensionAttribute3, extensionAttribute4, physicalDeliveryOfficeName, department, extensionAttribute1, employeeid, EmployeeType, whenCreated | where-object {$_.EmployeeType -ne $null -AND $_.mail -ne $null} |
foreach {
new-object psobject -Property @{
Email = $_.mail
firstName = $_.givenName
lastName = $_.sn
middleInitial = $_.initials
jobTitle = $_.title
Department = $_.department
UserID = $_.employeeid
}
} | Select Email,firstName,lastName,middleInitial,jobTitle,Department,UserID
$goodEmail = @()
$badEmail = @()
foreach ($user in $users) {
if($users.'Email' -ne "*@example.com") {
$goodEmail += $user
}
else {
$badEmail += $user
}
}
$goodEmail | Export-CSV $csvOriginal -NoTypeInformation -Append
$badEmail | Export-CSV $badEmails -NoTypeInformation -Append
Hi, I would try changing - if($users.'Email' -ne "@example.com") to if($user.Email -notlike "@example.com"). From memory I dont think you can use -eq/-ne with wildcards. You are also using the array and not the single object when comparing the data. – CraftyB – 2019-06-12T16:24:32.823
@CraftyB This is just my most recent iteration. I forgot to mention, obviously, I have tried -like, -notlike, and the current form and every version continues to dump into the single threaded file. – Kevin – 2019-06-12T16:35:34.093