Unable to get the AD users created in the past 1 year which is not contains the specific Domain name pattern:
$laterThan = (Get-Date).AddYears(-1)
$filter = { (whenCreated -gt $laterThan) -and (userPrincipalName -notcontain $((Get-ADDomain).Name)) }
$properties = 'canonicalName', 'whenCreated', 'displayName', 'lastlogondate'
Get-ADUser -Filter $filter -Properties $properties
Error showing as:
Get-ADUser : Error parsing query: ' (whenCreated -gt $laterThan) -and (userPrincipalName -notcontain $((Get-ADDomain).Name)) ' Error Message: 'Operator Not supported: -notcontain' at position: '55'. At line:5 char:1
- Get-ADUser -Filter $filter -Properties $properties
+ CategoryInfo : ParserError: (:) [Get-ADUser], ADFilterParsingException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
contains
ornotcontains
the possible FilterOperator are"-eq" | "-le" | "-ge" | "-ne" | "-lt" | "-gt"| "-approx" | "-bor" | "-band" | "-recursivematch" | "-like" | "-notlike"
. Ref.: docs.microsoft.com/en-us/powershell/module/addsadministration/… – Paxz