Author Posts

May 10, 2016 at 4:49 am

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

May 10, 2016 at 5:48 am

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

May 10, 2016 at 11:17 am

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

May 10, 2016 at 11:27 am

try changing this

$ADUser = $ADUserPath.GetDirectoryEntry()

to this

$ADUser = $ADUserPath.Properties

May 12, 2016 at 6:46 am

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.