I need to get the Enabled AD Objects (Users & Computer) that does not include the specific name patterns.
How can I filter out or exclude some of the results using the Get-ADObject with the below Query?
Script:
Code: Select all
$Exclusions = @(
'SystemMailbox',
'HealthMailbox',
'Migration'
'Delete'
'Disabled'
)
Get-ADObject -Filter '(ObjectClass -eq "user" -or ObjectClass -eq "computer") -and Enabled -eq $true -and isRecycled -eq $false -and name -ne "Deleted Objects"' | Where-Object{$_.Name -notin $Exclusions}
1. When I add the Filter Enabled -eq $true, nothing is returned.
2. I wanted to exclude certain OU like ‘OU=Disabled Users‘
3. If the name contains anything like the above $Exclusions
Thank you in advance.