$scriptpath = GetScriptpath("usernamegoeshere")
?$scriptpath
Sleep 2
Function GetScriptPath($ADAccountName)
$filter=" where samAccountName='"+$ADAccountName+"' "
$AdoCon = CreateObject("ADODB.Connection")
$AdoCon.Provider = "ADsDSOObject"; Current credentials are used, as username and password aren't specified
$AdoCon.Open("Active Directory Provider"); Create ADO command object for the connection.
$AdoCommand = CreateObject("ADODB.Command")
$AdoCommand.ActiveConnection = $AdoCon
$AdoCommand.CommandText ="Select AdsPath, samAccountName, GroupType, Scriptpath, Department, " +
"physicalDeliveryOfficeName from 'LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")+"' "+$filter
;Other fields include: givenname, initials, sn, displayname, telephonenumber, wwwhomepage, url, postofficebox, postalcode, profilepath, homedrive
; homedirectory, homephone, pager, mobile, facsimiletelephonenumber, iphone, othertelephone, title, department, company, and others.
; Execute the query.
$Recordset = $AdoCommand.Execute
$ADlookupname=$recordset.Fields("samAccountName").value
If $ADlookupName <> $ADAccountName
$GetScriptpath = 13
Else
$GetScriptpath = $recordset.fields("scriptpath").value
EndIf
$adocon="0"
$adocommand="0"
$recordset="0"
EndFunction