
Originally Posted by
tri_94
hi there tried that and it worked for some however i noticed that within the OU students I've got other OU groups
how can i modify it to include these ou groups aswell?
Sixth Form
2000
2001
2002
2003
2004
2005
2006
2007
thanks
nick
Okay, you need to add another sub OU to your constants; like this:
Code:
Const DOMAIN = "dc=cordeauxcc,dc=internal"
Const TOPLEVEL_OU = "ou=Establishments"
Const LEVEL1_OU = "ou=CHS"
Const LEVEL2_OU = "ou=Students"
Const LEVEL3_OU = "ou=Sixth Form"
Then change the code further down so that you can run the program for the Student OU or the sub OUs. If you have an entry for LEVEL3_OU to match the name of your sub OUs within Students it will work on that sub OU, or leave as "" to run it against the Students OU only (hope that makes sense!).
Change code to:
Code:
If LEVEL3_OU = "" Then
strOUPath = LEVEL2_OU & "," & LEVEL1_OU & "," & TOPLEVEL_OU & "," & DOMAIN
Else
strOUPath = LEVEL3_OU & "," & LEVEL2_OU & "," & LEVEL1_OU & "," & TOPLEVEL_OU & "," & DOMAIN
End If
Here is the complete code, in case that's confusing:
Code:
'==========================================================================
' NAME: ExportDetails.vbs
'
' AUTHOR: Jim Williams
' DATE : 29/02/2008
'
' COMMENT: Gets username, email and USNChanged values for users in OU
'==========================================================================
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set log file path to current directory
Dim strLogFilePath, openFile
strLogFilePath = objShell.CurrentDirectory & "\ExportDetails.csv"
'Check if file exists, if not; create and add headings
If (objFSO.FileExists(strLogFilePath)) Then
WScript.Echo "The Export File already exists. Rename, or move the file, and run again."
WScript.Echo "Exiting..."
WScript.Quit
'Exit
Else
Set openFile = objFSO.OpenTextFile(strLogFilePath, ForWriting, True)
openFile.WriteLine "Username, Email, USNChanged"
openFile.Close
End If
Dim strReport
strReport = GetUserInfo()
'write report to file
Set openFile = objFSO.OpenTextFile(strLogFilePath, ForAppending, True)
openFile.Write strReport
openFile.Close
WScript.Echo "Complete. Export file written to " & strLogFilePath
'tidy up
Set objShell = Nothing
Set objFSO = Nothing
Function GetUserInfo()
Const DOMAIN = "dc=cordeauxcc,dc=internal"
Const TOPLEVEL_OU = "ou=Establishments"
Const LEVEL1_OU = "ou=CHS"
Const LEVEL2_OU = "ou=Students"
Const LEVEL3_OU = "ou=Sixth Form"
Dim objOU, strOUPath, user
Dim objUSNChanged, dblUSNChanged
Dim strMyReport
On Error Resume Next
If LEVEL3_OU = "" Then
strOUPath = LEVEL2_OU & "," & LEVEL1_OU & "," & TOPLEVEL_OU & "," & DOMAIN
Else
strOUPath = LEVEL3_OU & "," & LEVEL2_OU & "," & LEVEL1_OU & "," & TOPLEVEL_OU & "," & DOMAIN
End If
Set objOU = GetObject _
("LDAP://" & strOUPath)
For Each user In objOU
Set objUSNChanged = user.Get("uSNChanged")
dblUSNChanged = Abs(objUSNChanged.HighPart * (2^32) + objUSNChanged.LowPart)
strMyReport = strMyReport & user.sAMAccountName & ", " & user.mail & ", " & dblUSNChanged & VbCrLf
Next
'tidy and return
Set objOU = Nothing
Set objUSNChanged = Nothing
GetUserInfo = strMyReport
End Function