get-aduser info

This topic contains 5 replies, has 2 voices, and was last updated by  Anthony Stringer 2 years, 1 month ago.

  • Author
  • #38837

    Wilfredo Perez

    I need to run a GPO that will collect info from the user that logs in. The user logs into the computer gets the samaccountname and uses get-aduser to collect full name and email address. My question is: If the client machine does not have the ad module do I need to import it or will the server handle it

  • #38848

    Anthony Stringer

    i do not know whether this will be handled by the workstation or the server, but i do know that you don't need the ad module to get the information you mentioned

    $userinfo = [pscustomobject][hashtable]([adsisearcher]"samaccountname=$env:USERNAME").findone().properties
  • #38900

    Wilfredo Perez

    This is what I have so far:

    $username = $env:USERNAME
    $Filter = "(&(objectCategory=User)(SamAccountName=$UserName))"
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher
    $Searcher.Filter = $Filter
    $ADUserPath = $Searcher.Findone()
    $ADUser = $ADUserPath.GetDirectoryEntry()
    $ADDisplayName = $ADUser.displayName
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title 
    $ADDescription = $ADUser.description 
    $ADTelePhoneNumber = $ADUser.TelephoneNumber 
    #$ADMobile = $ 
    $ADStreetAddress = $ADUser.streetaddress 
    #$ADCity = $ADUser.l 
    $ADDepartment = $ADUser.department 

    The only one that works and returns a value is displayname. Can someone help me fix it

  • #38901

    Anthony Stringer

    try changing this

    $ADUser = $ADUserPath.GetDirectoryEntry()

    to this

    $ADUser = $ADUserPath.Properties
  • #38998

    Wilfredo Perez

    How can I get the same properties with adsi. as with get-aduser .I can get the emailaddress property using get-aduser but not with adsi. Can You help me.

  • #38999

    Anthony Stringer

You must be logged in to reply to this topic.