Solved

Powershell Find empty EmployeeID of User with certain emailaddress

Posted on 2014-11-25
6
714 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 250 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 250 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 250 total points
ID: 40464555
@Subsun, thanks for the catch on " -Properties * "
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
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

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 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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

719 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