What's the best way (fast) get users by employeeNumber

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.
Post Reply
User avatar
mpeled
Posts: 4
Joined: Mon Dec 04, 2017 1:35 am

What's the best way (fast) get users by employeeNumber

Post by mpeled » Thu Dec 07, 2017 4:25 am

I want to get all users that dont have employeeNumber ,
is any way to get it faster then over one by one and check it?

I work with PowerShell GUI 2017
my script that i try it:

$de = New-Object directoryservices.DirectoryEntry("GC://dc=mylan,dc=local")
$ds = new-object directoryservices.directorysearcher($de)
$ds.propertiestoload.add("distinguishedname") > $null
$ds.filter = "(&(objectclass=user)(!employeeNumber=*))"
$ds.propertiestoload.add("distinguishedname") > $null
$fu = $ds.FindAll()

$arr = New-Object directoryservices.DirectoryEntry("LDAP://" + $fu.properties.distinguishedname[0])

User avatar
jvierra
Posts: 11549
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: What's the best way (fast) get users by employeeNumber

Post by jvierra » Thu Dec 07, 2017 4:57 am

This is how to search the Global catalog. Note how we set up the filter and the GC connection.

Code: Select all

$searcher = [adsisearcher]'(&(objectclass=user)(objectcategory=person)(!employeeNumber=*))'
$searcher.$searcher = [adsi]'GC://dc=mylan,dc=local'
[void]$searcher.propertiestoload.add('distinguishedname')
$searcher.FindAll() | ForEach-Object{ $_.Properties['distinguishedname'] }
This returns a list of all user accounts. You will want to add extra filters to ermove mailboxes and other non-human accounts.

User avatar
mpeled
Posts: 4
Joined: Mon Dec 04, 2017 1:35 am

Re: What's the best way (fast) get users by employeeNumber

Post by mpeled » Thu Dec 07, 2017 11:35 am

jvierra wrote:
Thu Dec 07, 2017 4:57 am
This is how to search the Global catalog. Note how we set up the filter and the GC connection.

Code: Select all

$searcher = [adsisearcher]'(&(objectclass=user)(objectcategory=person)(!employeeNumber=*))'
$searcher.$searcher = [adsi]'GC://dc=mylan,dc=local'
[void]$searcher.propertiestoload.add('distinguishedname')
$searcher.FindAll() | ForEach-Object{ $_.Properties['distinguishedname'] }
This returns a list of all user accounts. You will want to add extra filters to ermove mailboxes and other non-human accounts.
Work Grate thanks.

one more Questions,
need function for convert employeeNumber to samaccountname

User avatar
jvierra
Posts: 11549
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: What's the best way (fast) get users by employeeNumber

Post by jvierra » Thu Dec 07, 2017 4:36 pm

Hah! I just remembered that I have an old demo of how to get users and change attribute values.

See attached:
Attachments
Demo-ADUpdateForm.psf
(27.23 KiB) Downloaded 3 times

Post Reply