First thing to make sure is you have the proper module installed. If you get any errors running the cmdlet(s) below, make sure you have the following module installed:
Run the following command in Powershell
Install-WindowsFeature RSAT-AD-PowerShell -IncludeAllSubFeature
Here are a couple different examples that essentially give you the same result.
DsQuery and Get-ADObject seem to be neck-to-neck in terms of performance, however the output is MUCH easier to work with using Get-AdObject so I would recommend that.
CLS
$properties = @('givenname', 'initials', 'mobile', 'telephonenumber', 'sn', 'displayname', 'company', 'title', 'mail', 'department', 'samaccountname')
Clear-Variable A, B, C, D -Force -Confirm:$False -ErrorAction SilentlyContinue
(Measure-Command {
$A = (dsquery * -filter "(&(samAccountType=805306368)(|(mobile=*)(telephonenumber=*)))" -limit 0 -attr $properties).trim() | select -skip 1
}).TotalMilliseconds
(Measure-Command {
$searcher = [adsisearcher]::new()
$searcher.Sort.PropertyName = "sn"
$searcher.PageSize = 10000
$searcher.Filter = "(&(samAccountType=805306368)(|(mobile=*)(telephonenumber=*)))"
$searcher.PropertiesToLoad.AddRange($properties)
$B = ($searcher.FindAll().Properties)
}).TotalMilliseconds
(Measure-Command {
$C = (Get-ADObject -LDAPFilter "(&(samAccountType=805306368)(|(mobile=*)(telephonenumber=*)))" -Properties $properties)
}).TotalMilliseconds
(Measure-Command {
$D = (Get-ADUser -LDAPFilter "(&(samAccountType=805306368)(|(mobile=*)(telephonenumber=*)))" -Properties $properties)
}).TotalMilliseconds