Submitted By: Chester Martin Jr.

Lists all Microsoft MOM computer groups. Dependencies include: 1) A system DSN named MOMDB to access the database; and, 2) D:\Scripts\ComputerGroups\Groups must exist.

Visual Basic
Edit|Remove
Const adOpenStatic     = 3
Const adLockOptimistic = 3
Const adUseClient      = 3

Set FSO                = Wscript.CreateObject("Scripting.FileSystemObject")

Set objConnection      = CreateObject("ADODB.Connection")
Set objRecordset       = CreateObject("ADODB.Recordset")
Set WshShell           = WScript.CreateObject("WScript.Shell")

objConnection.Open "DSN=MomDB;"
objRecordset.CursorLocation = adUseClient


' ********************************************
'
'       Delete Last Results from folder
'
' ********************************************

FSO.DeleteFile("D:\Scripts\ComputerGroups\Groups\*.txt"), DeleteReadOnly


' ********************************************
'
'         Pull ComputerGroups
'
' ********************************************

objRecordset.Open "SELECT Computer, [Rule] FROM ComputerToComputerRuleView ORDER BY Computer", objConnection, adOpenStatic, adLockOptimistic

Do While not objRecordset.EOF
  For Each Record In objRecordset.Fields
    
    If Record.Name = "Computer" Then
      Server = Record
    End If
    
    If Record.Name = "Rule" Then
      ComputerGroup = Record
    End If
    
  Next
  WScript.Echo Server & " - " & ComputerGroup
  
  IF FSO.FileExists("D:\Scripts\ComputerGroups\Groups\" & ComputerGroup & ".txt") Then
    Set File = FSO.OpenTextFile("D:\Scripts\ComputerGroups\Groups\" & ComputerGroup & ".txt",8)
  Else
    Set File = FSO.CreateTextFile("D:\Scripts\ComputerGroups\Groups\" & ComputerGroup & ".txt")
  End If  
  File.WriteLine Server
  File.Close
  
  objRecordset.MoveNext
Loop    
 
objRecordset.Close

objConnection.Close