Skip to content

Instantly share code, notes, and snippets.

@lazywinadmin
Created May 17, 2014 16:54
Show Gist options
  • Select an option

  • Save lazywinadmin/b827b2a94e8089aa1520 to your computer and use it in GitHub Desktop.

Select an option

Save lazywinadmin/b827b2a94e8089aa1520 to your computer and use it in GitHub Desktop.
getdomainuser_phonenumber3.ps1
function Get-DomainUser
{
PARAM ($DisplayName,[Adsi]$SearchRoot= "LDAP://OU=Servers,OU=TEST,dc=fx,dc=lab")
$Search = [adsisearcher]"(&(objectCategory=person)(objectClass=User)(displayname=$DisplayName))"
$Search.searchRoot = $SearchRoot
foreach ($user in $($Search.FindAll()))
{
New-Object -TypeName PSObject -Property @{
"DisplayName" = $user.properties.displayname -as [string]
"UserName" = $user.properties.samaccountname -as [string]
"Description" = $user.properties.description -as [string]
"TelephoneNumber" = (($user.properties.telephonenumber -as [string]).Substring(4))
}
}
}
Get-DomainUser -DisplayName "*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment