Link to home
Start Free TrialLog in
Avatar of PBIT
PBITFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try the following:
Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain, DC=com" -Properties department

Open in new window

Avatar of PBIT

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.ActiveDirectory.Management.Commands.GetADUser
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PBIT

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.