msperano
2010-05-05 12:41:48 UTC
This seems to be asked alot. I have been using this script to export A
objmembers (users) to excell and works great. What I would also like t
do is add groupmemberships to the same script to add another row in th
excel output. I found a bunch of scripts that will do the groups b
themselves and show members. Can anyone help combine these two scripts.
Thanks
Mike
I attached the two scripts, User Exports Works Great.txt is the workin
one and I would like to combine the Group Membership with it.
****First working one******
Dim ObjWb
Dim ObjExcel
Dim x, zz
Set objRoot = GetObject("LDAP://ROotDSE")
strDNC = objRoot.Get("DefaultNamingContext")
'strOU = InputBox("Enter the name of an OU")
Set objDomain = GetObject("LDAP://" & strDNC)
'Set objDomain = GetObject("LDAP://ou=" & strOU & "," & strDNC) ' Bin
to the top of the Domain using LDAP using ROotDSE
Call ExcelSetup("Sheet1") ' Sub to make Excel Document
x = 1
Call enummembers(objDomain)
Sub enumMembers(objDomain)
On Error Resume Next
Dim Secondary(20) ' Variable to store the Array of 2ndary email alias'
For Each objMember In objDomain ' go through the collection
If ObjMember.Class = "user" Then ' if not User object, move on.
x = x +1 ' counter used to increment the cells in Excel
objwb.Cells(x, 1).Value = objMember.Class
' I set AD properties to variables so if needed you could do Nul
checks or add if/then's to this code
' this was done so the script could be modified easier.
SamAccountName = ObjMember.samAccountName
Cn = ObjMember.CN
FirstName = objMember.GivenName
LastName = objMember.sn
'Profile = objMember.profilePath
'LoginScript = objMember.scriptpath
HomeDirectory = ObjMember.HomeDirectory
HomeDrive = ObjMember.homeDrive
AdsPath = Objmember.Adspath
LastLogin = objMember.LastLogin
zz = 1 ' Counter for array of 2ndary email addresses
For each email in ObjMember.proxyAddresses
If Left (email,5) = "SMTP:" Then
Primary = Mid (email,6) ' if SMTP is all caps, then it's the Primary
ElseIf Left (email,5) = "smtp:" Then
Secondary(zz) = Mid (email,6) ' load the list of 2ndary SMT
emails into Array.
zz = zz + 1
End If
Next
' Write the values to Excel, using the X counter to increment the rows
objwb.Cells(x, 2).Value = SamAccountName
objwb.Cells(x, 3).Value = CN
objwb.Cells(x, 4).Value = FirstName
objwb.Cells(x, 5).Value = LastName
'objwb.Cells(x, 6).Value = Profile
'objwb.Cells(x, 7).Value = LoginScript
objwb.Cells(x, 8).Value = HomeDirectory
objwb.Cells(x, 9).Value = HomeDrive
objwb.Cells(x, 10).Value = Adspath
objwb.Cells(x, 11).Value = LastLogin
' Write out the Array for the 2ndary email addresses.
For ll = 1 To 20
objwb.Cells(x,26+ll).Value = Secondary(ll)
Next
' Blank out Variables in case the next object doesn't have a value fo
the property
SamAccountName = "-"
Cn = "-"
FirstName = "-"
LastName = "-"
Profile = "-"
LoginScript = "-"
HomeDirectory = "-"
HomeDrive = "-"
For ll = 1 To 20
Secondary(ll) = ""
Next
End If
' If the AD enumeration runs into an OU object, call the Sub again t
itinerate
If objMember.Class = "organizationalUnit" or OBjMember.Class
"container" Then
enumMembers (objMember)
End If
Next
End Sub
Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and add
Column heads to the 1st row
Set objExcel = CreateObject("Excel.Application")
Set objwb = objExcel.Workbooks.Add
Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName)
Objwb.Name = "Active Directory Users" ' name the sheet
objwb.Activate
objExcel.Visible = True
objwb.Cells(1, 2).Value = "SamAccountName"
objwb.Cells(1, 3).Value = "CN"
objwb.Cells(1, 4).Value = "FirstName"
objwb.Cells(1, 5).Value = "LastName"
'objwb.Cells(1, 6).Value = "Profile"
'objwb.Cells(1, 7).Value = "LoginScript"
objwb.Cells(1, 8).Value = "HomeDirectory"
objwb.Cells(1, 9).Value = "HomeDrive"
objwb.Cells(1, 10).Value = "Adspath"
objwb.Cells(1, 11).Value = "LastLogin"
End Sub
MsgBox "Done" ' show that script is complete
******Second one*****
Set objUser=GetObject("LDAP://CN=Mike Sperano," & _
"OU=Mike Test OU,DC=FCSD,DC=local")
Set colGroups = objUser.Groups
For Each objGroup in colGroups
Wscript.Echo objGroup.CN
GetNested(objGroup)
Next
Function GetNested(objGroup)
On Error Resume Next
colMembers = objGroup.GetEx("memberOf")
For Each strMember in colMembers
strPath = "LDAP://" & strMember
Set objNestedGroup = _
GetObject(strPath)
WScript.Echo objNestedGroup.CN
GetNested(objNestedGroup)
Next
End Function
+-------------------------------------------------------------------+
|Filename: Group Membership6.txt |
|Download: http://forums.techarena.in/attachment.php?attachmentid=10890|
+-------------------------------------------------------------------+
objmembers (users) to excell and works great. What I would also like t
do is add groupmemberships to the same script to add another row in th
excel output. I found a bunch of scripts that will do the groups b
themselves and show members. Can anyone help combine these two scripts.
Thanks
Mike
I attached the two scripts, User Exports Works Great.txt is the workin
one and I would like to combine the Group Membership with it.
****First working one******
Dim ObjWb
Dim ObjExcel
Dim x, zz
Set objRoot = GetObject("LDAP://ROotDSE")
strDNC = objRoot.Get("DefaultNamingContext")
'strOU = InputBox("Enter the name of an OU")
Set objDomain = GetObject("LDAP://" & strDNC)
'Set objDomain = GetObject("LDAP://ou=" & strOU & "," & strDNC) ' Bin
to the top of the Domain using LDAP using ROotDSE
Call ExcelSetup("Sheet1") ' Sub to make Excel Document
x = 1
Call enummembers(objDomain)
Sub enumMembers(objDomain)
On Error Resume Next
Dim Secondary(20) ' Variable to store the Array of 2ndary email alias'
For Each objMember In objDomain ' go through the collection
If ObjMember.Class = "user" Then ' if not User object, move on.
x = x +1 ' counter used to increment the cells in Excel
objwb.Cells(x, 1).Value = objMember.Class
' I set AD properties to variables so if needed you could do Nul
checks or add if/then's to this code
' this was done so the script could be modified easier.
SamAccountName = ObjMember.samAccountName
Cn = ObjMember.CN
FirstName = objMember.GivenName
LastName = objMember.sn
'Profile = objMember.profilePath
'LoginScript = objMember.scriptpath
HomeDirectory = ObjMember.HomeDirectory
HomeDrive = ObjMember.homeDrive
AdsPath = Objmember.Adspath
LastLogin = objMember.LastLogin
zz = 1 ' Counter for array of 2ndary email addresses
For each email in ObjMember.proxyAddresses
If Left (email,5) = "SMTP:" Then
Primary = Mid (email,6) ' if SMTP is all caps, then it's the Primary
ElseIf Left (email,5) = "smtp:" Then
Secondary(zz) = Mid (email,6) ' load the list of 2ndary SMT
emails into Array.
zz = zz + 1
End If
Next
' Write the values to Excel, using the X counter to increment the rows
objwb.Cells(x, 2).Value = SamAccountName
objwb.Cells(x, 3).Value = CN
objwb.Cells(x, 4).Value = FirstName
objwb.Cells(x, 5).Value = LastName
'objwb.Cells(x, 6).Value = Profile
'objwb.Cells(x, 7).Value = LoginScript
objwb.Cells(x, 8).Value = HomeDirectory
objwb.Cells(x, 9).Value = HomeDrive
objwb.Cells(x, 10).Value = Adspath
objwb.Cells(x, 11).Value = LastLogin
' Write out the Array for the 2ndary email addresses.
For ll = 1 To 20
objwb.Cells(x,26+ll).Value = Secondary(ll)
Next
' Blank out Variables in case the next object doesn't have a value fo
the property
SamAccountName = "-"
Cn = "-"
FirstName = "-"
LastName = "-"
Profile = "-"
LoginScript = "-"
HomeDirectory = "-"
HomeDrive = "-"
For ll = 1 To 20
Secondary(ll) = ""
Next
End If
' If the AD enumeration runs into an OU object, call the Sub again t
itinerate
If objMember.Class = "organizationalUnit" or OBjMember.Class
"container" Then
enumMembers (objMember)
End If
Next
End Sub
Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and add
Column heads to the 1st row
Set objExcel = CreateObject("Excel.Application")
Set objwb = objExcel.Workbooks.Add
Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName)
Objwb.Name = "Active Directory Users" ' name the sheet
objwb.Activate
objExcel.Visible = True
objwb.Cells(1, 2).Value = "SamAccountName"
objwb.Cells(1, 3).Value = "CN"
objwb.Cells(1, 4).Value = "FirstName"
objwb.Cells(1, 5).Value = "LastName"
'objwb.Cells(1, 6).Value = "Profile"
'objwb.Cells(1, 7).Value = "LoginScript"
objwb.Cells(1, 8).Value = "HomeDirectory"
objwb.Cells(1, 9).Value = "HomeDrive"
objwb.Cells(1, 10).Value = "Adspath"
objwb.Cells(1, 11).Value = "LastLogin"
End Sub
MsgBox "Done" ' show that script is complete
******Second one*****
Set objUser=GetObject("LDAP://CN=Mike Sperano," & _
"OU=Mike Test OU,DC=FCSD,DC=local")
Set colGroups = objUser.Groups
For Each objGroup in colGroups
Wscript.Echo objGroup.CN
GetNested(objGroup)
Next
Function GetNested(objGroup)
On Error Resume Next
colMembers = objGroup.GetEx("memberOf")
For Each strMember in colMembers
strPath = "LDAP://" & strMember
Set objNestedGroup = _
GetObject(strPath)
WScript.Echo objNestedGroup.CN
GetNested(objNestedGroup)
Next
End Function
+-------------------------------------------------------------------+
|Filename: Group Membership6.txt |
|Download: http://forums.techarena.in/attachment.php?attachmentid=10890|
+-------------------------------------------------------------------+
--
msperano
------------------------------------------------------------------------
msperano's Profile: http://forums.techarena.in/members/216856.htm
View this thread: http://forums.techarena.in/server-scripting/1333960.htm
http://forums.techarena.in
msperano
------------------------------------------------------------------------
msperano's Profile: http://forums.techarena.in/members/216856.htm
View this thread: http://forums.techarena.in/server-scripting/1333960.htm
http://forums.techarena.in