?
Solved

Powershell Find empty EmployeeID of User with certain emailaddress

Posted on 2014-11-25
6
Medium Priority
?
792 Views
Last Modified: 2014-11-26
Hi,

I'm looking for a powershell script that will give me users with an empty EmployeeID AND an emailaddress of emaildomain "@powershell.xyz"

I tried things like:
import-module activedirectory

Get-ADUser -Filter  {(Enabled -eq "True") | where {`
 ($_.EmployeeID -eq $NULL) -and`
 ($_.mail -like "powershell.xyz")
 } |`
 Select-Object -Property SamAccountName, Name|`
 Sort-Object -Property Name |`
 export-CSV .\result.csv -nti 

Open in new window


This does not give any results.
I hope someone can help me on this one !

Thanks in advance
0
Comment
Question by:Loyall
[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

Assisted Solution

by:becraig
becraig earned 1000 total points
ID: 40464445
Not making any changes to your code other than to add the wildcard and to add an empty string reference.

import-module activedirectory

Get-ADUser -Filter  {(Enabled -eq "True") | where {
 ($_.EmployeeID -eq $NULL) -or ($_.EmployeeID -eq "") -and ($_.mail -like "*powershell.xyz")
 } | Select-Object -Property SamAccountName, Name|  Sort-Object -Property Name |  export-CSV .\result.csv -nti 

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 1000 total points
ID: 40464529
You are missing -Properties parameter and some small syntax errors.. Were condition wont work as there is no EmployeeID or Mail property passed to pipeline. -Properties * will allow you to pass all properties to pipeline..
Import-Module activedirectory
Get-ADUser -Filter {Enabled -eq "True"} -Properties * | where {
 ($_.EmployeeID -eq $NULL) -and `
 ($_.mail -like "*powershell.xyz")
 }|
 Select-Object -Property SamAccountName,Name |
 Sort-Object -Property Name |
 Export-CSV .\result.csv -nti

Open in new window

0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 1000 total points
ID: 40464555
@Subsun, thanks for the catch on " -Properties * "
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 40

Expert Comment

by:Subsun
ID: 40464712
No problem.. :-)
0
 
LVL 2

Author Comment

by:Loyall
ID: 40466715
Hi,

I will give it try tomorrow  and let you know !
0
 
LVL 2

Author Closing Comment

by:Loyall
ID: 40468473
Works like a charm.
Thanks !
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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

743 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