Re: Problem with script
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 22 Aug 2007 15:18:30 -0500
The OU names in the file OUNames.txt must be full Distinguished Names. Some
examples, if you domain is MyDomain.com:
ou=West,ou=Sales,dc=MyDomain,dc=com
ou=East,ou=Sales,dc=MyDomain,dc=com
ou=Sales,dc=MyDomain,dc=com
ou=Engr,dc=MyDomain,dc=com
ou=West,ou=Engr,dc=MyDomain,dc=com
cn=Users,dc=MyDomain,dc=com
There really is no other way to uniquely identify the OU objects in AD. For
example, there are two OU's with Relative Distinguished Names "ou=West" in
my example. This would be common in a large organization. My last example,
and the one that seems to have raised an error for you, is actually a
container rather than an OU, but that's OK. Both containers and OU objects
are "containers" and the code will enumerate the users inside.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"Shiloh" <Shiloh@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:43A57CF8-07B4-4698-9882-360D39537DBE@xxxxxxxxxxxxxxxx
I have a problem with the script below.
I'm trying to export a list of users per OU to a file by reading from a
text
file with the OU's in it, but I receive the following error, can anyone
please help me out with this. This is a sample script that I found
somewhere
in these forums.
Thank you very much
"Line 18
Char 9
ActiveX component can't create object:'LDAP://cn=Users'
Code 800A01AD
Source Microsoft VBScript Runtime Error"
'This script will list All AD Users to a text files"
Const ForAppending = 8
Const ForReading = 1
' Open file of OU DN's for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile("c:\Scripts\Input\OUNames.txt",
ForReading)
' Open output file.
Set objOutput = objFSO.OpenTextFile("c:\Scripts\Output\Users per OU.txt",
ForAppending, True)
' Read input file.
Do Until objInput.AtEndOfStream
' Read DN of OU.
strOU = Trim(objInput.ReadLine)
' Skip blank lines.
If (strOU <> "") Then
' Bind to OU object.
Set objOU = CreateObject("LDAP://" & strOU)
' Output name of OU.
objOutput.WriteLine "OU: " & objOU.distinguishedName
' Filter on user objects.
objOU.Filter = Array("user")
' Enumerate users.
For Each objUser in objOU
objOutput.WriteLine objUser.sAMAccountName
Next
End If
Loop
' Clean up.
objInput.Close
objOutput.Close
.
- Prev by Date: Search for especific files (without WMI)
- Next by Date: creating users with naming convention
- Previous by thread: Search for especific files (without WMI)
- Next by thread: creating users with naming convention
- Index(es):
Relevant Pages
|
Loading