Solved

Powershell Find empty EmployeeID of User with certain emailaddress

Posted on 2014-11-25
6
551 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

17 Experts available now in Live!

Get 1:1 Help Now