PBIT
asked on
Help with PowerShell Script
Hello,
I am trying to filter out accounts in Active Directory with no titles in them. So, I want to pull only users with titles. If titles are empty, they should not be retrieved. I have this below but the title -eq $null is not working. Can you help?
Get-ADUser -Filter {enabled -eq "true" and title -eq $null} -SearchBase "DC=domain, DC=com" -Properties department
I am trying to filter out accounts in Active Directory with no titles in them. So, I want to pull only users with titles. If titles are empty, they should not be retrieved. I have this below but the title -eq $null is not working. Can you help?
Get-ADUser -Filter {enabled -eq "true" and title -eq $null} -SearchBase "DC=domain, DC=com" -Properties department
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get the follow:
Get-ADUser : Error parsing query: 'enabled -eq "true" and title -like "*"' Error Message: 'syntax error' at position:
'20'.
At line:1 char:1
+ Get-ADUser -Filter {enabled -eq "true" and title -like "*"} -SearchBase "DC=domain...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~
+ CategoryInfo : ParserError: (:) [Get-ADUser], ADFilterParsingException
+ FullyQualifiedErrorId : Error parsing query: 'enabled -eq "true" and title -like "*"' Error Message: 'syntax err
or' at position: '20'.,Microsoft.ActiveDire ctory.Mana gement.Com mands.GetA DUser
Get-ADUser : Error parsing query: 'enabled -eq "true" and title -like "*"' Error Message: 'syntax error' at position:
'20'.
At line:1 char:1
+ Get-ADUser -Filter {enabled -eq "true" and title -like "*"} -SearchBase "DC=domain...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADUser], ADFilterParsingException
+ FullyQualifiedErrorId : Error parsing query: 'enabled -eq "true" and title -like "*"' Error Message: 'syntax err
or' at position: '20'.,Microsoft.ActiveDire
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, I got it right now.
My example had all the correct syntax and should have been accepted as the answer. If you wanted to split points we becraig for explicitly pointing out that "and" needed the hyphen in front of it, that's fine, but title -eq $null results in an error.
Open in new window