|
|
|||||||
Hi guys, I try to read some attribute from AD, such as lastlogontimestamp. When I run the script. the result is [complex object] Is there a way that can output the correct result? the script as below. Code: $selectedProperties = "displayName,lastLogonTimestamp" $propertynames = Split($selectedProperties,",") $oCn = CreateObject("ADODB.Connection") $oCmd = CreateObject("ADODB.Command") $oCn.Provider = "ADsDSOObject" $ = $oCn.Open("Active Directory Provider", "", "", -1) $oCmd.ActiveConnection = $oCn $oCmd.Properties("Page Size").Value = 1000 $oCmd.Properties("Searchscope").Value = 2 ;ADS_SCOPE_SUBTREE $oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://contoso.com/CN=test,OU=Users,OU=test,DC=contoso,DC=com' WHERE objectCategory='user' ORDER BY Name" $oRS = $oCmd.Execute While Not $oRS.EOF For $i = 0 to UBound($propertynames) If VarType($oRS.Fields($propertyNames[$i]).Value) = 9 Or VarType($oRS.Fields($propertyNames[$i]).Value) >= 8192 ? "[Complex Object]" Else ? $oRS.Fields($propertyNames[$i]).Value EndIf Next $oRS.MoveNext Loop |
||||||||
|
|
|||||||
There is an easier way to get this data. Please see the code below I Code: CLS Break on $username = @USERID $userhome = TranslateName(3, "", 3, @LDomain + "\" + $username, 1) $userinfo = GetObject("LDAP://" + $userhome[0]) ? "General Info" ? "------------" ? " " ? "First Name: " + $userinfo.givenName ? "Initials: " + $userinfo.initials ? "Last Name: " + $userinfo.sn ? "Full Name: " + $userinfo.FullName ? "Display Name: " + $userinfo.displayName ? "Account Name: " + $userinfo.sAMAccountName ? "Distinguished Name: " + $userinfo.distinguishedName ? "Description: " + $userinfo.Description ? "Office Location: " + $userinfo.physicalDeliveryOfficeName ? "Email: " + $userinfo.mail ? "Web Page: " + $userinfo.wwwHomePage ? "Street: " + $userinfo.streetAddress ? "Postal Code: " + $userinfo.postalCode ? "Post Office Box: " + $userinfo.postOfficeBox ? "City: " + $userinfo.l ? "State or Province: " + $userinfo.st ? "Country or Region: " + $userinfo.co ? "Home Phone: " + $userinfo.homePhone ? "Pager: " + $userinfo.pager ? "Mobile Phone: " + $userinfo.mobile ? "Telephone Number: " + $userinfo.telephoneNumber ? "Fax Number: " + $userinfo.facsimileTelephoneNumber ? "Notes: " + $userinfo.info ? "Title: " + $userinfo.title ? "Department: " + $userinfo.department ? "Company Name: " + $userinfo.company ? "Principal Name: " + $userinfo.userPrincipalName ? " " ? "Profile Info" ? "------------" ? " " ? "Profile Path: " + $userinfo.profilePath ? "Script Path: " + $userinfo.scriptPath ? "Home Directory: " + $userinfo.homeDirectory ? "Home Drive: " + $userinfo.homeDrive ? "Terminal Services Profile Path: " + $userinfo.TerminalServicesProfilePath ? "Terminal Services Local Path: " + $userinfo.TerminalServicesHomeDirectory ? "Terminal Services Home Drive: " + $userinfo.TerminalServicesHomeDrive ? "Terminal Services Allowed: " + $userinfo.AllowLogon ? " " ? "Account Info" ? "------------" ? " " ? "User Account Control: " + $userinfo.userAccountControl ? "Account Disabled: " + $userinfo.AccountDisabled ? "Account Locked: " + $userinfo.IsAccountLocked ? "Account Created: " + $userinfo.whenCreated ? "Account Last Modified: " + $userinfo.whenChanged ? "Account Expires: " + $userinfo.AccountExpirationDate ? "Last Login: " + $userinfo.LastLogin ? "Last Failed Login: " + $userinfo.LastFailedLogin ? "Logon Count: " + $userinfo.logonCount ? "Bad Login Count: " + $userinfo.BadLoginCount ? "Password Last Changed: " + $userinfo.PasswordLastChanged ? 'Press a key...' Get $ ; TranslateName function authored by Howard A. Bullock Function TranslateName($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType) Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType Dim $NameTranslate, $ReturnName, $Error, $ErrorText $Error = 0 $ErrorText = "" $ReturnName = "" $NameTranslate = CreateObject("NameTranslate") $Error = @error $ErrorText = @serror If $Error = 0 $NameTranslate.Init($InitType, $BindName) $Error = @error $ErrorText = @serror If $Error = 0 $NameTranslate.Set($LookupNameType, $LookupName) $Error = @error $ErrorText = @serror If $Error = 0 $ReturnName = $NameTranslate.Get($ReturnNameType) $Error = @error $ErrorText = @serror EndIf EndIf EndIf $TranslateName = $ReturnName, $Error, $ErrorText EndFunction |