Mombu the Microsoft Forum

Go Back   Mombu the Microsoft Forum > Microsoft > Problem with DGSET GROUP report
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 30th October 07:46
External User
 
Posts: 1
Default Problem with DGSET GROUP report



I made a simple batch file to get a list of machines belonging to
certain groups, save it to a file then open it in Excel.

See below:

dsget group "cn=AdobeAcrobat9,ou=*,ou=Groups,ou=*,DC=*,DC= *" -members -
expand | sort > "c:\documents and settings\%username%\desktop
\spreadsheetname.xls
start excel.exe "c:\documents and settings\%username%\desktop
\spreadsheetname.xls


It works but the output is ugly with it displaying a bunch of info
about the path that to the OU that I don't need to look at, and, at
the same time, there is a bit more info I want that I can't get it to
display.

It has the following problems.

1. Excel fails to seperate the OU info into seperate cells despite
the info being seperated by commas. (I'd like to solve this comma
seperation or just not show this info).

2. I need to get the "description" field of the computers, but when I
try to add "desc" to dsget it gives the description field of the
AdobeAcrobat9 group instead the description field of each of the
members of the group.

3. I really don't need it to display all the OU info. All I'd like
it do is save a list of the machine names that belong to the
AdobeAcrobat9 group in a format Excel can display elegantly and in
alphabetical order. The description field of each of the member
computers should be displayed in the same row as the computer name.

How can this be done?
Can it be done with a simple bat file or does it have to be a vbs
script?
  Reply With Quote


 


2 30th October 07:47
kuma
External User
 
Posts: 1
Default Problem with DGSET GROUP report



This can be done extremely easily in powershell with Quest's Active
Directory cmdlets.
#Get the group, access the member collection
(Get-QADGroup -SearchRoot "ou=*,ou=Groups,ou=*,DC=*,DC=*" -Name
"AdobeAcrobat9").Member `
#Foreach member get the corresponding ad entry
| Foreach-object {Get-QADComputer $_} `
#select only name and description
| Select name,description `
export results to the csv file
| Export-CSV -Path "c:\documents and settings\$env:username\desktop
\spreadsheetname.csv" -NoTypeInformation

#Open the file in excel
Invoke-Item "c:\documents and settings\$env:username\desktop
\spreadsheetname.csv"

Thats by far the easiest way i can think of to do it. Hope its helpful.
  Reply With Quote
3 30th October 07:47
External User
 
Posts: 1
Default Problem with DGSET GROUP report


I've never seen Quest cmdlets before and all the domain controllers
are Server 2003. There is no Server 2008 or powershell available.
So, this new Quest software would need to be installed on on
everyone's machine that needs to use that method to create the report?
  Reply With Quote
4 30th October 07:47
richard mueller [mvp]
External User
 
Posts: 1
Default Problem with DGSET GROUP report


It may be possible to do this with dsquery and dsget, but I tried for some
time and failed. Some of my attempts failed if any members of the group were
users (objects of class other than computer). A bigger problem might be that
these commands are only available on W2k3 DC's (and above). I would use a
VBScript program similar to:
==========
Option Explicit
Dim objGroup, objMember, strName
Dim strExcelPath, objExcel, objSheet, intRow

' Spreadsheet file to be created.
strExcelPath = "c:\scripts\Computers.xls"

' Bind to Excel object.
Set objExcel = CreateObject("Excel.Application")

' Create a new workbook.
objExcel.Workbooks.Add

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Bind to the group object.
Set objGroup =
GetObject("LDAP://cn=AdobeAcrobat9,ou=*,ou=Groups,ou=*,DC=*,DC=*")

' Enumerate direct members.
intRow = 1
For Each objMember In objGroup.Members
If (objMember.Class = "computer") Then
' Retrieve NetBIOS name of computer.
strName = objMember.sAMAccountName
' Strip off trailing "$"
strName = Left(strName, Len(strName) - 1)
objSheet.Cells(intRow, 1).Value = strName
objSheet.Cells(intRow, 2).Value = objMember.description
intRow = intRow + 1
End If
Next

objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close
========
  Reply With Quote
5 30th October 07:47
richard mueller [mvp]
External User
 
Posts: 1
Default Problem with DGSET GROUP report


First, you may be able to use Joe Richards' free adfind utility for this:

http://www.joeware.net/freetools/tools/adfind/index.htm

This still has the drawback that people that use it need the tool, but at
least it's one exe. PowerShell requires .NET framework, PowerShell, and the
cmdlets.

Next, I just noticed you used -expand to reveal nested group members. In
VBScript we can do the same thing with a recursive subroutine:
=======
Option Explicit
Dim objGroup
Dim strExcelPath, objExcel, objSheet, intRow

' Spreadsheet file to be created.
strExcelPath = "c:\scripts\Computers.xls"

' Bind to Excel object.
Set objExcel = CreateObject("Excel.Application")

' Create a new workbook.
objExcel.Workbooks.Add

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Bind to the group object.
Set objGroup =
GetObject("LDAP://cn=AdobeAcrobat9,ou=*,ou=Groups,ou=*,DC=*,DC=*")

' Enumerate members.
intRow = 1
Call GetMembers(objGroup)

objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close

Sub GetMembers(objParent)
' Recursive subroutine to enumerate nested group membership.
' objSheet and intRow must have global scope.
Dim objParent, strName

For Each objMember In objParent.Members
If (objMember.Class = "computer") Then
' Retrieve NetBIOS name of computer.
strName = objMember.sAMAccountName
' Strip off trailing "$"
strName = Left(strName, Len(strName) - 1)
objSheet.Cells(intRow, 1).Value = strName
objSheet.Cells(intRow, 2).Value = objMember.description
intRow = intRow + 1
End If
If (objMember.Class = "group") Then
Call GetMembers(objMember)
End If
Next
End Sub

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
  Reply With Quote
6 30th October 07:47
External User
 
Posts: 1
Default Problem with DGSET GROUP report


I saved it as a vbs file, tried it and it fails with a message:
"Variable is undefined: 'objMember'
  Reply With Quote
7 30th October 07:47
External User
 
Posts: 1
Default Problem with DGSET GROUP report


Nevermind, I figured out how to declare the variables and it works.
It runs successfully and saves the info to a file.
However, it doesn't work using the %username% path to the desktop or
automatically launch the file my original batch file though.
How can I have launch automatically so the user doesn't have to go
hunt for the file and click on it?
  Reply With Quote
8 8th November 17:16
kuma
External User
 
Posts: 1
Default Problem with DGSET GROUP report


Powershell can run on 2k3 XP 2k8 and Vista, it just doesn't come
installed by default. The quest active directory cmdlets are free to
download and can make working with AD much simpler. Each computer that
you would want to make the report on would need to have it installed
though.
  Reply With Quote
Reply


Thread Tools
Display Modes




666