VBscript display users profile within OU

Posted on 2008-11-06
Last Modified: 2012-06-21
Hi there, I am looking for VBscript that display users profile within OU. Can anyone help me please? Thanks
Question by:2LL
    LVL 65

    Accepted Solution

    Hi, which profile details are you after?  This script will output the user's name and profilepath attributes for each user in a specific OU.

    You need to change
    strOU = "OU=Users,OU=TestOU,"

    to specify an OU path, in reverse order.  For example, the above refers to

    Run the below script with
    cscript C:\MyScript.vbs

    to see the output better.


    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =   CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strOU = "OU=Users,OU=TestOU,"
    If strOU <> "" Then
    	If Right(strOU, 1) <> "," Then strOU = strOU & ","
    End If
    strDNSDomain = strOU & objRootDSE.Get("defaultNamingContext")
    objCommand.CommandText = _
        "SELECT Name,ProfilePath FROM '" & strDNSDomain & "' WHERE objectCategory='user'"
    Set objRecordSet = objCommand.Execute
    Do Until objRecordSet.EOF
        Wscript.Echo objRecordSet.Fields("Name").Value & ": " & objRecordSet.Fields("ProfilePath").Value

    Open in new window


    Author Comment

    I found another script, I did not test your script yet, but I gave you all the point anyway. Thank you very much for your help.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now