Solved

Help with PowerShell Script

Posted on 2014-09-03
6
229 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
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 transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

867 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

20 Experts available now in Live!

Get 1:1 Help Now