Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

Powershell Find empty EmployeeID of User with certain emailaddress

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
Loyall
Asked:
Loyall
  • 2
  • 2
  • 2
3 Solutions
 
becraigCommented:
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
 
SubsunCommented:
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
 
becraigCommented:
@Subsun, thanks for the catch on " -Properties * "
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
SubsunCommented:
No problem.. :-)
0
 
LoyallAuthor Commented:
Hi,

I will give it try tomorrow  and let you know !
0
 
LoyallAuthor Commented:
Works like a charm.
Thanks !
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now