Page 1 of 1 1
Topic Options
#193646 - 2009-05-01 05:24 PM LDAP Query Again
5861king Offline
Fresh Scripter

Registered: 2006-09-28
Posts: 48
Loc: UK
Hi there got this code however I'm haveing some problems displaying accounts that are locked. I was wondering if someone can modify this code to display accounts thats are locked.

 Code:
$selectedProperties = "displayName"
$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://domain.co.uk' WHERE objectCategory='user' AND displayName = 'username' AND objectCategory = 'Person' AND objectClass = '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 
 


Many Thanks

Top
#193647 - 2009-05-01 10:38 PM Re: LDAP Query Again [Re: 5861king]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Try it this way.

 Code:
	$Usr = GetObject("WinNT://"+@DOMAIN+"/"+$User)
	$Nul = $usr.IsAccountLocked
_________________________
Today is the tomorrow you worried about yesterday.

Top
#193648 - 2009-05-02 12:15 AM Re: LDAP Query Again [Re: Gargoyle]
5861king Offline
Fresh Scripter

Registered: 2006-09-28
Posts: 48
Loc: UK
Thanks for that Gargoyle,

I alread have the Winnt script which unlocks the accounts however its very slow, I would like to use the LDAP method which is much quicker at query the AD accounts, I'm sure there is a way!!

Top
#193649 - 2009-05-02 12:44 AM Re: LDAP Query Again [Re: 5861king]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Here is a vbscript version: http://www.microsoft.com/technet/scriptcenter/resources/qanda/may05/hey0512.mspx
It seems like to me this has been discussed before... you might do a little digging in the board search on some of the keywords within the script to see if someone has already converted it to kix.

Top
#193650 - 2009-05-02 01:49 AM Re: LDAP Query Again [Re: Allen]
5861king Offline
Fresh Scripter

Registered: 2006-09-28
Posts: 48
Loc: UK
How about this bit of scipt have i coded it correctly as it does not see to work.

 Code:
  
WHERE objectCategory='user' AND displayName = 'username' AND objectCategory = 'Person' AND objectClass = 'User' & ' userAccountControl:1.2.840.113556.1.4.803:=2' ORDER BY Name"


Edited by 5861king (2009-05-02 01:50 AM)

Top
#193688 - 2009-05-05 05:29 PM Re: LDAP Query Again [Re: 5861king]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This seems to work great..

I did a query for IsAccountLocked and found the following..

 Code:
cls
break on
$username = "testuser"
$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


Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#193739 - 2009-05-07 10:10 PM Re: LDAP Query Again [Re: Kdyer]
5861king Offline
Fresh Scripter

Registered: 2006-09-28
Posts: 48
Loc: UK
Thanks Kdyer,

I did do a search but I just dont know how I missed this one!!!
just what I was looking for. \:\)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 492 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.153 seconds in which 0.112 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org