Solved

Help with PowerShell Script

Posted on 2014-09-03
6
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 40

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 40

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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