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])
What's the best way (fast) get users by employeeNumber
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.
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.
Re: What's the best way (fast) get users by employeeNumber
This is how to search the Global catalog. Note how we set up the filter and the GC connection.
This returns a list of all user accounts. You will want to add extra filters to ermove mailboxes and other non-human accounts.
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'] }
Re: What's the best way (fast) get users by employeeNumber
Work Grate thanks.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.
This returns a list of all user accounts. You will want to add extra filters to ermove mailboxes and other non-human accounts.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'] }
one more Questions,
need function for convert employeeNumber to samaccountname
Re: What's the best way (fast) get users by employeeNumber
Hah! I just remembered that I have an old demo of how to get users and change attribute values.
See attached:
See attached:
- Attachments
-
- Demo-ADUpdateForm.psf
- (27.23 KiB) Downloaded 89 times