Solved

Help with PowerShell Script

Posted on 2014-09-03
6
231 Views
Last Modified: 2014-09-03
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
0
Comment
Question by:PBIT
  • 2
  • 2
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40301805
Get-ADUser -Filter {enabled -eq "true" -and title -eq $null} -SearchBase "DC=domain, DC=com" -Properties department 

Open in new window

"and" needs to be "-and"
0
 
LVL 39

Expert Comment

by:footech
ID: 40301819
Try the following:
Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain, DC=com" -Properties department

Open in new window

0
 

Author Comment

by:PBIT
ID: 40301923
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
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 29

Assisted Solution

by:becraig
becraig earned 500 total points
ID: 40301933
It seems you did not read my post above:
At line:1 char:1
+ Get-ADUser -Filter {enabled -eq "true" [b]and [/b]title -like "*"} -SearchBase "DC=domain...

Open in new window


"and" needs to be "-and"
0
 

Author Comment

by:PBIT
ID: 40301985
Sorry, I got it right now.
0
 
LVL 39

Expert Comment

by:footech
ID: 40302159
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.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question