1
votes

Why does Powershell say that a supported operator is not supported?

I have the following (simplified) code containing a case-sensitive not-equal operator:

$filter_accountchanged = { (sAMAccountName -eq $username) -and (GivenName -cne $givenname) }
try {
        if (Get-ADUser -filter $filter_accountchanged) { # update aduser }
catch {
        Write-host $_.Exception

In what situations can this result in the following error that I am seeing?

Microsoft.ActiveDirectory.Management.ADFilterParsingException: Error parsing query: ' (sAMAccountName -eq $username) -and ((GivenName -cne $givenname))' Error Message: 'Operator Not supported: -cne' at position: '50'. at Microsoft.ActiveDirectory.Management.QueryParser.yyparse() at Microsoft.ActiveDirectory.Management.QueryParser..ctor(String query, VariableExpressionConverter varExpressionConverter, ConvertSearchFilterDelegate searchFilterConverterDelegate) at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.BeginProcessingOverride()

The query succeeds when I remove the c from cne.

2

2 Answers

2
votes

Unfortunately not all operators are supported by Powershell's filter param. Your filter will/does work with a | Where() statement (it did on my local system).

Powershell filter support list from 2011 (which lists "ne" as an option)

0
votes

This is a limitation of the Get-ADUser Filter parameter, not PowerShell's in particular. Try -ne instead.