locked
How to Add objectGUID into this vbscript RRS feed

  • Question

  • Hi,

    I've been struggling for some while and I tend to do that before i give up and ask for help =(.... Well here I am. What I'm trying to do is get a full report from my AD. Came across this site that posted this script below. I've made adjustments and got it working great for someone Else's use. Now for my use it wont work. I Need to record GUID, SID and history if possible. Can someone take a look and let me know what changes you think I should make? I wont post the modified version but if i see what you put I can place it in the right place on my modified version. (just my luck I manage to get it to work for someone else but not for myself).

    I assume the objects should be:

    objectGUID,objectSid,sIDHistory

    Here is the full script:

    OPTION EXPLICIT
    
    dim FileName, multivaluedsep,strAttributes
    dim strFilter, strRoot, strScope
    dim cmd, rs,cn
    dim objRoot, objFSO,objCSV
    dim comma, q, i, j, mvsep, strAttribute, strValue
    
    ' ********************* Setup *********************
    
    ' The filename of the csv file produced by this script
    FileName ="userexport.csv"
    ' Seperator used for multi-valued attributes
    multivaluedsep = ";"
    ' comma seperated list of attributes to export
    strAttributes = "sAMAccountName,givenName,sn,displayName,description,physicalDeliveryOfficeName," & _
    		"telephoneNumber,mail,cn"
    
    ' Default filter for all user accounts (ammend if required)
    strFilter = "(&(objectCategory=person)(objectClass=user))"
    ' scope of search (default is subtree - search all child OUs)
    strScope = "subtree"
    ' search root. e.g. ou=MyUsers,dc=wisesoft,dc=co,dc=uk
    ' leave blank to search from domain root
    strRoot = ""
    
    ' *************************************************
    q = """"
    
    set cmd = createobject("ADODB.Command")
    set cn = createobject("ADODB.Connection")
    set rs = createobject("ADODB.Recordset")
    
    cn.open "Provider=ADsDSOObject;"
    cmd.activeconnection = cn
    
    if strRoot = "" then
    	set objRoot = getobject("LDAP://RootDSE")
    	strRoot = objRoot.get("defaultNamingContext") 
    end if
    
    cmd.commandtext = "<LDAP://" & strRoot & ">;" & strFilter & ";" & _
    		  strAttributes & ";" & strScope 
    
    '**** Bypass 1000 record limitation ****
    cmd.properties("page size")=1000
    
    set rs = cmd.execute
    set objFSO = createobject("Scripting.FileSystemObject")
    set objCSV = objFSO.createtextfile(FileName)
    
    comma = "" ' first column does not require a preceding comma
    i = 0 
    
    ' create a header row and count the number of attributes
    for each strAttribute in SPLIT(strAttributes,",")
    	objcsv.write(comma & q & strAttribute & q)
    	comma = "," ' all columns apart from the first column require a preceding comma
    	i = i + 1
    next
    On Error Resume Next
    ' for each item returned by the Active Directory query
    while rs.eof <> true and rs.bof <> true
    	comma="" ' first column does not require a preceding comma
    	objcsv.writeline ' Start a new line
    	' For each column in the result set
    	for j = 0 to (i - 1)
    		select case typename(rs(j).value)
    		case "Null" ' handle null value
    			objcsv.write(comma & q & q)
    		case "Variant()" ' multi-valued attribute
    			' Multi-valued attributes will be seperated by value specified in
    			' "multivaluedsep" variable
    			mvsep = "" 'No seperator required for first value
    			objcsv.write(comma & q)
    			for each strValue in rs(j).Value
    				' Write value
    				' single double quotes " are replaced by double double quotes ""
    				objcsv.write(mvsep & replace(strValue,q,q & q))
    				mvsep = multivaluedsep ' seperator used when more than one value returned
    			next
    			objcsv.write(q)
    		case else
    			' Write value
    			' single double quotes " are replaced by double double quotes ""
    			objcsv.write(comma & q & replace(rs(j).value,q,q & q) & q)
    		end select
    		
    		comma = "," ' all columns apart from the first column require a preceding comma
    	next
    	rs.movenext
    wend
    
    ' Close csv file and ADO connection
    cn.close
    objCSV.Close
    
    wscript.echo "Finished"
    
    

    I get weird errors if I don't use
     On Error Resume Next


    • Moved by Bill_Stewart Monday, June 30, 2014 5:31 PM Abandoned
    Friday, February 7, 2014 11:41 PM

All replies

  • Since you do not know scripting I recommend skipping VBScript and learning PowerShell.

    Start here: http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Module-for-08769c67


    ¯\_(ツ)_/¯

    Saturday, February 8, 2014 12:17 AM
  • Her is the basic way to get these items in PowerShell.

    get-aduser -filter * -properties * | select sid,guid,sidhistory

    That's it.


    ¯\_(ツ)_/¯

    Saturday, February 8, 2014 12:25 AM
  • Her is the basic way to get these items in PowerShell.

    get-aduser -filter * -properties * | select sid,guid,sidhistory

    That's it.


    ¯\_(ツ)_/¯

    Hi,

    Thanks for this. I actually thought about doing it in powershell. The only problem is not all users who need this script would be able to use powershell.

    Monday, February 10, 2014 5:08 PM
  • Then do it with VBScript.  The properties are the same.

    ¯\_(ツ)_/¯

    Monday, February 10, 2014 7:54 PM