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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mpeled
Posts: 5
Last visit: Sat Dec 30, 2017 11:08 pm

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

Post by mpeled »

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])
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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: 5
Last visit: Sat Dec 30, 2017 11:08 pm

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

Post by mpeled »

jvierra wrote: Thu Dec 07, 2017 3: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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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 89 times
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked