Solved

Powershell Find empty EmployeeID of User with certain emailaddress

Posted on 2014-11-25
6
457 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 28

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 28

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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