vbs script to export users from within a directory.

  • Thread starter Thread starter TJ_2006
  • Start date Start date
T

TJ_2006

Hi there,

Below is a script i pulled off the ms tech net i am having sereous
trouble using it, it gets a error on " Set OutPutFile =
FileSystem.CreateTextFile("marketing.txt", True)", it says there is an
invaled number of arguements when there isnt, if i change the dc=lan
to anything else i get the error "a referrel from the server was
made", which is what id expect considering the fully qualified domain
is etc.lan so nothing else will work.

is this a bug im confused id appreiate it if anyone can shed some
light on this

Regards James scammell

'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("marketing.txt", True)
SetoContainer=GetObject("LDAP://OU=techies,DC=etc,DC=lan")
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub EnumerateUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
If Not IsEmpty(oUser.distinguishedName) Then
OutPutFile.WriteLine "dn: " & oUser.distinguishedName
End If
If Not IsEmpty(oUser.name) Then
OutPutFile.WriteLine "name: " & oUser.Get ("name")
End If
'need to do this because oUser.name would get back the Relative
Distinguished name (CN=joe)
If Not IsEmpty(oUser.st) Then
OutPutFile.WriteLine "st: " & oUser.st
End If
If Not IsEmpty(oUser.streetAddress) Then
OutPutFile.WriteLine "streetAddress: " & oUser.streetAddress
End If
Case "organizationalunit" , "container"
EnumerateUsers oUser
End Select
OutPutFile.WriteLine
Next
End Sub
 
The error is on the next line, where there is no space between the Set and
the oContainer.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"TJ_2006" <James.Scammell@gmail.com> wrote in message
news:1184519123.095015.84700@w3g2000hsg.googlegroups.com...
> Hi there,
>
> Below is a script i pulled off the ms tech net i am having sereous
> trouble using it, it gets a error on " Set OutPutFile =
> FileSystem.CreateTextFile("marketing.txt", True)", it says there is an
> invaled number of arguements when there isnt, if i change the dc=lan
> to anything else i get the error "a referrel from the server was
> made", which is what id expect considering the fully qualified domain
> is etc.lan so nothing else will work.
>
> is this a bug im confused id appreiate it if anyone can shed some
> light on this
>
> Regards James scammell
>
> 'Global variables
> Dim oContainer
> Dim OutPutFile
> Dim FileSystem
> 'Initialize global variables
> Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
> Set OutPutFile = FileSystem.CreateTextFile("marketing.txt", True)
> SetoContainer=GetObject("LDAP://OU=techies,DC=etc,DC=lan")
> 'Enumerate Container
> EnumerateUsers oContainer
> 'Clean up
> OutPutFile.Close
> Set FileSystem = Nothing
> Set oContainer = Nothing
> WScript.Echo "Finished"
> WScript.Quit(0)
> Sub EnumerateUsers(oCont)
> Dim oUser
> For Each oUser In oCont
> Select Case LCase(oUser.Class)
> Case "user"
> If Not IsEmpty(oUser.distinguishedName) Then
> OutPutFile.WriteLine "dn: " & oUser.distinguishedName
> End If
> If Not IsEmpty(oUser.name) Then
> OutPutFile.WriteLine "name: " & oUser.Get ("name")
> End If
> 'need to do this because oUser.name would get back the Relative
> Distinguished name (CN=joe)
> If Not IsEmpty(oUser.st) Then
> OutPutFile.WriteLine "st: " & oUser.st
> End If
> If Not IsEmpty(oUser.streetAddress) Then
> OutPutFile.WriteLine "streetAddress: " & oUser.streetAddress
> End If
> Case "organizationalunit" , "container"
> EnumerateUsers oUser
> End Select
> OutPutFile.WriteLine
> Next
> End Sub
>
 
Back
Top