get-aduser info

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Anthony Stringer Anthony Stringer 4 months, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #38837
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    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
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    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
    $userinfo.name
    $userinfo.mail
    
    #38900
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    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 = $ADUser.mobile 
    $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
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    try changing this

    $ADUser = $ADUserPath.GetDirectoryEntry()
    

    to this

    $ADUser = $ADUserPath.Properties
    
    #38998
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    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
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.