I am trying to get a list of AD-Users in different domains but cannot find a way to exclude users that has "Health" in their name for an example.
This is how my query looks like as of now:
#$excludedusers = @('HealthMailbox123456')
Get-ADUser -Server $test -Credential $1cred -Filter{enabled -eq $true} | Where-Object { $_.DistinguishedName -notlike '*OU=.Service Accounts,*' } | Select-object Samaccountname,surname,givenname | Where { $excludedusers -NotContains$_.Samaccountname }
As of now, "HealthMailbox123456" is excluded but only because I typed the entire name.
Is there a way to exclude every user having "Health" in their name?