Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Active Directory > Re: Find user account owner in bulk

Reply
Thread Tools Display Modes

Re: Find user account owner in bulk

 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      05-12-2010

"sk8er_boi" <> wrote in message
news:...
>
> Hi all ... greetings of the day,
>
> I'm working as an system admin a company having abt 50000 users on AD &
> need to provide owner (creator) of almost all accounts on AD. I know i
> can find this info on Security tab > advanced > owner tab on user
> properties but i cannot do this for so many users !!! is there any way
> to find user owner in bulk ?
>
> can i run a conditional search on AD for eg. owner=SysAdmin or any
> script that will simply scan all accounts & list the owner ...pls help
> !
>
> P.s : we use Quest Active Roles Server for AD operations & have limited
> rights on native mode
>
>
> --
> sk8er_boi
> ------------------------------------------------------------------------
> sk8er_boi's Profile: http://forums.techarena.in/members/219435.htm
> View this thread: http://forums.techarena.in/active-directory/1336370.htm
>
> http://forums.techarena.in
>


Unfortunately, you cannot simply query for the owner. As far as I know you
must bind to each object, then bind to the security descriptor object and
retrieve the owner property. A VBScript program can use ADO to retrieve the
DN of all users, bind to the objects, and output DN and owner of each. Run
the below at a command prompt so you can redirect the output to a text file.
I had the script output DN and owner semicolon delimited (DN's have embedded
commas) so the output can be read into a spreadsheet. If desired, you could
replace distinguishedName with sAMAccountName throughout to output
"pre-Windows 2000 logon" name instead.
============
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN
Dim objUser, objSecurityDescriptor

' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory forest.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("rootDomainNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on all users.
strFilter = "(&(objectCategory=person)(objectClass=user))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strDN = adoRecordset.Fields("distinguishedName").Value
strDN = Replace(strDN, "/", "\/")
' Bind to the object.
Set objUser = GetObject("LDAP://" & strDN)
' Bind to security object.
Set objSecurityDescriptor = objUser.Get("ntSecurityDescriptor")
' Display user and owner.
Wscript.Echo objUser.distinguishedName & ";" &
objSecurityDescriptor.Owner
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      05-12-2010


"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
>
> "sk8er_boi" <> wrote in message
> news:...
>>
>> Hi all ... greetings of the day,
>>
>> I'm working as an system admin a company having abt 50000 users on AD &
>> need to provide owner (creator) of almost all accounts on AD. I know i
>> can find this info on Security tab > advanced > owner tab on user
>> properties but i cannot do this for so many users !!! is there any way
>> to find user owner in bulk ?
>>
>> can i run a conditional search on AD for eg. owner=SysAdmin or any
>> script that will simply scan all accounts & list the owner ...pls help
>> !
>>
>> P.s : we use Quest Active Roles Server for AD operations & have limited
>> rights on native mode
>>
>>
>> --
>> sk8er_boi
>> ------------------------------------------------------------------------
>> sk8er_boi's Profile: http://forums.techarena.in/members/219435.htm
>> View this thread: http://forums.techarena.in/active-directory/1336370.htm
>>
>> http://forums.techarena.in
>>

>
> Unfortunately, you cannot simply query for the owner. As far as I know you
> must bind to each object, then bind to the security descriptor object and
> retrieve the owner property. A VBScript program can use ADO to retrieve
> the DN of all users, bind to the objects, and output DN and owner of each.
> Run the below at a command prompt so you can redirect the output to a text
> file. I had the script output DN and owner semicolon delimited (DN's have
> embedded commas) so the output can be read into a spreadsheet. If desired,
> you could replace distinguishedName with sAMAccountName throughout to
> output "pre-Windows 2000 logon" name instead.
> ============
> Option Explicit
>
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
> Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN
> Dim objUser, objSecurityDescriptor
>
> ' Setup ADO objects.
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> Set adoCommand.ActiveConnection = adoConnection
>
> ' Search entire Active Directory forest.
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("rootDomainNamingContext")
> strBase = "<LDAP://" & strDNSDomain & ">"
>
> ' Filter on all users.
> strFilter = "(&(objectCategory=person)(objectClass=user))"
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "distinguishedName"
>
> ' Construct the LDAP syntax query.
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> adoCommand.CommandText = strQuery
> adoCommand.Properties("Page Size") = 100
> adoCommand.Properties("Timeout") = 30
> adoCommand.Properties("Cache Results") = False
>
> ' Run the query.
> Set adoRecordset = adoCommand.Execute
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
> ' Retrieve values.
> strDN = adoRecordset.Fields("distinguishedName").Value
> strDN = Replace(strDN, "/", "\/")
> ' Bind to the object.
> Set objUser = GetObject("LDAP://" & strDN)
> ' Bind to security object.
> Set objSecurityDescriptor = objUser.Get("ntSecurityDescriptor")
> ' Display user and owner.
> Wscript.Echo objUser.distinguishedName & ";" &
> objSecurityDescriptor.Owner
> ' Move to the next record in the recordset.
> adoRecordset.MoveNext
> Loop
>
> ' Clean up.
> adoRecordset.Close
> adoConnection.Close
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>



As suggested by kj, I see that Joe Richards' adfind does its usual magic and
easily retrieves the owner property. The syntax is:

adfind -default -f "(&(objectCategory=person)(objectClass=user))" -ownercsv

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
kj [SBS MVP]
Guest
Posts: n/a

 
      05-12-2010

Richard Mueller [MVP] wrote:
> "Richard Mueller [MVP]" <rlmueller-> wrote
> in message news:...
>>
>> "sk8er_boi" <> wrote in message
>> news:...
>>>
>>> Hi all ... greetings of the day,
>>>
>>> I'm working as an system admin a company having abt 50000 users on
>>> AD & need to provide owner (creator) of almost all accounts on AD.
>>> I know i can find this info on Security tab > advanced > owner tab
>>> on user properties but i cannot do this for so many users !!! is
>>> there any way to find user owner in bulk ?
>>>
>>> can i run a conditional search on AD for eg. owner=SysAdmin or any
>>> script that will simply scan all accounts & list the owner ...pls
>>> help !
>>>
>>> P.s : we use Quest Active Roles Server for AD operations & have
>>> limited rights on native mode
>>>
>>>
>>> --
>>> sk8er_boi
>>> ------------------------------------------------------------------------
>>> sk8er_boi's Profile: http://forums.techarena.in/members/219435.htm
>>> View this thread:
>>> http://forums.techarena.in/active-directory/1336370.htm
>>> http://forums.techarena.in
>>>

>>
>> Unfortunately, you cannot simply query for the owner. As far as I
>> know you must bind to each object, then bind to the security
>> descriptor object and retrieve the owner property. A VBScript
>> program can use ADO to retrieve the DN of all users, bind to the
>> objects, and output DN and owner of each. Run the below at a command
>> prompt so you can redirect the output to a text file. I had the
>> script output DN and owner semicolon delimited (DN's have embedded
>> commas) so the output can be read into a spreadsheet. If desired,
>> you could replace distinguishedName with sAMAccountName throughout
>> to output "pre-Windows 2000 logon" name instead. ============
>> Option Explicit
>>
>> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
>> Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN
>> Dim objUser, objSecurityDescriptor
>>
>> ' Setup ADO objects.
>> Set adoCommand = CreateObject("ADODB.Command")
>> Set adoConnection = CreateObject("ADODB.Connection")
>> adoConnection.Provider = "ADsDSOObject"
>> adoConnection.Open "Active Directory Provider"
>> Set adoCommand.ActiveConnection = adoConnection
>>
>> ' Search entire Active Directory forest.
>> Set objRootDSE = GetObject("LDAP://RootDSE")
>> strDNSDomain = objRootDSE.Get("rootDomainNamingContext")
>> strBase = "<LDAP://" & strDNSDomain & ">"
>>
>> ' Filter on all users.
>> strFilter = "(&(objectCategory=person)(objectClass=user))"
>>
>> ' Comma delimited list of attribute values to retrieve.
>> strAttributes = "distinguishedName"
>>
>> ' Construct the LDAP syntax query.
>> strQuery = strBase & ";" & strFilter & ";" & strAttributes &
>> ";subtree" adoCommand.CommandText = strQuery
>> adoCommand.Properties("Page Size") = 100
>> adoCommand.Properties("Timeout") = 30
>> adoCommand.Properties("Cache Results") = False
>>
>> ' Run the query.
>> Set adoRecordset = adoCommand.Execute
>>
>> ' Enumerate the resulting recordset.
>> Do Until adoRecordset.EOF
>> ' Retrieve values.
>> strDN = adoRecordset.Fields("distinguishedName").Value
>> strDN = Replace(strDN, "/", "\/")
>> ' Bind to the object.
>> Set objUser = GetObject("LDAP://" & strDN)
>> ' Bind to security object.
>> Set objSecurityDescriptor = objUser.Get("ntSecurityDescriptor")
>> ' Display user and owner.
>> Wscript.Echo objUser.distinguishedName & ";" &
>> objSecurityDescriptor.Owner
>> ' Move to the next record in the recordset.
>> adoRecordset.MoveNext
>> Loop
>>
>> ' Clean up.
>> adoRecordset.Close
>> adoConnection.Close
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>

>
>
> As suggested by kj, I see that Joe Richards' adfind does its usual
> magic and easily retrieves the owner property. The syntax is:
>
> adfind -default -f "(&(objectCategory=person)(objectClass=user))"
> -ownercsv
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net


Thanks for the nice script Richard and gentle reminder about "owner"
security vs attribute.

--
/kj


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong with my live.com account? Michael Elliott Windows Live Mail 43 1 Week Ago 09:36 PM
Move \Users folder once for all Peter Meinl Windows Vista Installation 25 03-03-2010 01:37 AM
Security Failures after Password Change Zachary Server Security 14 10-30-2009 06:02 PM
Administrator Account is Already in Use as Main Account? Kcpirana Windows Vista Administration 12 05-17-2007 06:06 PM
Renamed Guest Account - Yikes! Jerry L Windows Vista Administration 13 04-20-2007 11:36 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59