+ Post New Thread
Results 1 to 14 of 14
Learning Network Manager Thread, Exporting From Active Directory in Technical; Hi there, i need to export some information from AD, and i require the following mailnickname Email Address USNCHANGED i've ...
  1. #1
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    115
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    16

    Exporting From Active Directory

    Hi there, i need to export some information from AD,

    and i require the following

    mailnickname
    Email Address
    USNCHANGED

    i've tried CSVDE -f C:\export.csv -l "mailnickname,mail,usnchanged"

    however i only get the mailnickname and the mail information

    any ideas anyone.

    thanks
    nick

  2. #2

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,800
    Thank Post
    110
    Thanked 582 Times in 503 Posts
    Blog Entries
    1
    Rep Power
    223
    What is your domains functional level?

  3. #3
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    24
    You could run the following vbscript. Just change the domain name and OU info to suit your domain. Doing it this way allows you to run it for each OU. Hope this helps.

    Code:
    Const DOMAIN = "dc=your_domain,dc=your_area,dc=sch,dc=uk"
    Const TOPLEVEL_OU = "ou=School Users"
    Const LEVEL1_OU = "ou=Staff Accounts"
    Const LEVEL2_OU = "ou=staff2"
    
    Dim objOU
    Dim strOUPath
    Dim user
    Dim strDictUser
    Dim objUSNChanged, dblUSNChanged
    
    On Error Resume Next
    
    strOUPath = LEVEL2_OU & "," & LEVEL1_OU & "," & TOPLEVEL_OU & "," & DOMAIN
    Set objOU = GetObject _
    	("LDAP://" & strOUPath)
    
    For Each user In objOU
    	WScript.Echo "Username: " & user.sAMAccountName
    	WScript.Echo "Mail nickname: " & user.mailNickname
    	WScript.Echo "Email: " & user.mail
    	Set objUSNChanged = user.Get("uSNChanged")
    	dblUSNChanged = Abs(objUSNChanged.HighPart * (2^32) + objUSNChanged.LowPart)
    	WScript.Echo "USNChanged: " & dblUSNChanged & VbCrLf
    Next
    
    Set objOU = nothing
    Set dblUSNChanged = nothing

  4. #4
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    115
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    16
    sorry new to this part, what do you mean?

  5. #5
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    24
    Quote Originally Posted by tri_94 View Post
    sorry new to this part, what do you mean?
    PM me with your domain name and the OU containing the users that you want to get the info for. If it's a sub OU I'll need the name of the OUs above it. I'll edit the script so you can see what I mean.

  6. #6

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,800
    Thank Post
    110
    Thanked 582 Times in 503 Posts
    Blog Entries
    1
    Rep Power
    223
    Quote Originally Posted by tri_94 View Post
    sorry new to this part, what do you mean?
    Technet - What Are Active Directory Functional Levels?

    You need a minimum domain functional level of Windows 2000 native otherwise usnchanged is not recorded in AD.

    Additionally, usnchanged is not replicated, so you must always query the same DC.

    Polling for Changes Using USNChanged (Windows)

  7. #7
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    115
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    16
    Hi there again, sorry to be so vague about this.

    We are installing some software called Safe com for monitoring printing and our finance officer has agreed to trial a system called pull printing. which is were the pupils have a pin number and they type in at the printer and then it slows a list of what they have sent to print and then you can choose which you like.

    So I've got a choice of supplying a csv file with all pupils names and email addresses and a pin number. however if i can use the USNChanged number i can integrate it to create a pin when i create a new user rather then manually doing it.

    So what i require is to export details such as mailnickname, (which is our pupils usernames) and mail (which is our email address). and also I've seen that the uSNChanged is a unique number..

    I'm a bit of a beginner to most of the AD side of things as we have a RM network here.

    from what i understand this will be the information i will need to use ?

    OU=Domain Controllers,DC=cordeauxcc,DC=internal

    OU=Establishments,OU=Domain Controllers,DC=cordeauxcc,DC=internal

    OU=Students,OU=CHS,OU=Establishments,DC=cordeauxcc ,DC=internal

    DC=cordeauxcc,DC=internal

    thanks for any help
    nick

  8. #8
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    24
    Okay, give this a try.

    Copy the code into Notepad and save it as a .vbs file. Open a cmd prompt and run the script.

    It'll write the result to a csv file in the same directory as the one the script is run from.

    I'm not sure that USNChanged is the value you want as this will change when user attributes change. You could generate auto numbers in Excel?

    Let me know if you have any problems.

    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"
    	
    	Dim objOU, strOUPath, user
    	Dim objUSNChanged, dblUSNChanged
    	Dim strMyReport
    	
    	On Error Resume Next
    	
    	strOUPath = LEVEL2_OU & "," & LEVEL1_OU & "," & TOPLEVEL_OU & "," & DOMAIN
    	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
    Last edited by altecsole; 23rd April 2008 at 01:47 PM.

  9. Thanks to altecsole from:

    speckytecky (23rd April 2008)

  10. #9
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    115
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    16
    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

  11. #10
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    24
    Quote Originally Posted by tri_94 View Post
    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

  12. Thanks to altecsole from:

    leeshellard (5th June 2008)

  13. #11
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    115
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    16
    hi there, tried that and it worked fine for the Sixth Form and also 2007, yet it didn't work for 2006 or 2005. so I've exported the entire AD to csv and uploaded it adusers.rar.

    hope someone can work out where I've gone wrong

    thanks
    nick
    Attached Files Attached Files

  14. #12
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    24
    Quote Originally Posted by tri_94 View Post
    hi there, tried that and it worked fine for the Sixth Form and also 2007, yet it didn't work for 2006 or 2005. so I've exported the entire AD to csv and uploaded it adusers.rar.

    hope someone can work out where I've gone wrong

    thanks
    nick
    Looking at your AD structure I can't see any reason why it wouldn't work.

    Did you set the Const correctly? You need to make sure you have the 'ou=' bit in as well. So, for 2005, you should have:

    Code:
    Const LEVEL3_OU = "ou=2005"

  15. Thanks to altecsole from:

    tri_94 (24th April 2008)

  16. #13
    tri_94's Avatar
    Join Date
    Feb 2007
    Location
    Lincolnshire
    Posts
    115
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    16
    hi there, yeah got it working, i wasnt waiting long enough for the export. many thanks for all your help

    cheers
    nick

  17. #14
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Morecambe, Lancashire, UK.
    Posts
    281
    Thank Post
    39
    Thanked 36 Times in 26 Posts
    Rep Power
    24
    Quote Originally Posted by tri_94 View Post
    hi there, yeah got it working, i wasnt waiting long enough for the export. many thanks for all your help

    cheers
    nick
    No problem, glad I could help.

SHARE:
+ Post New Thread

Similar Threads

  1. Active Directory question
    By ClaireL in forum Windows
    Replies: 14
    Last Post: 19th May 2008, 12:38 PM
  2. Replies: 7
    Last Post: 31st January 2008, 12:17 PM
  3. Active Directory Problem
    By clarky2k3 in forum Windows
    Replies: 12
    Last Post: 24th January 2008, 09:58 AM
  4. active directory all messed up
    By alonebfg in forum Windows
    Replies: 2
    Last Post: 7th January 2008, 08:25 PM
  5. PDA and Active Directory
    By localzuk in forum Windows
    Replies: 4
    Last Post: 10th October 2007, 03:54 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •