Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

VBscript display users profile within OU

Hi there, I am looking for VBscript that display users profile within OU. Can anyone help me please? Thanks
0
2LL
Asked:
2LL
1 Solution
 
RobSampsonCommented:
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
domain.com/TestOU/Users

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

to see the output better.

Regards,

Rob.
Const ADS_SCOPE_SUBTREE = 2
 
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
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value & ": " & objRecordSet.Fields("ProfilePath").Value
    objRecordSet.MoveNext
Loop

Open in new window

0
 
2LLAuthor Commented:
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.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now