Solved

Help with PowerShell Script

Posted on 2014-09-03
6
227 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 28

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now