Re: Problem with script



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



.



Relevant Pages

  • RE: log print jobs
    ... I know that doing it in cmd is very easy, ... I only tested the script couple of times, but it seems to return the right ... It is simple to write the output to a txt file (or csv): ... Const ForAppending = 8 ...
    (microsoft.public.scripting.vbscript)
  • Re: Writing variables to a text file
    ... Want a script to write your documentation? ... > Set SPItems = objWMIService.ExecQuery("Select * from ... > For Each objItem in OSItems ...
    (microsoft.public.scripting.vbscript)
  • Need help with log ( text ) file - write vs append
    ... I want to log what the script has done. ... 'Set objFile = objFSO.OpenTextFile(strOutPutFile, ForWriting, True) ... Const ForAppending = 8 ...
    (microsoft.public.scripting.vbscript)
  • Adding multiple UOs in AD tree
    ... I work for a county school system and have been asked to go through ... three sub containers underneath. ... Is there a script that I could modify, ... can take a decent example and modify to fit my needs if one exists. ...
    (microsoft.public.windows.server.scripting)
  • Adding multiple UOs in AD tree
    ... I work for a county school system and have been asked to go through ... three sub containers underneath. ... Is there a script that I could modify, ... can take a decent example and modify to fit my needs if one exists. ...
    (microsoft.public.windows.server.active_directory)

Loading