CONST arrResourceID = 0, arrMachineName = 1, arrUserID = 2, arrMax = 2 CONST ForReading = 1, ForWriting = 2 dim oShell Set objArgs = WScript.Arguments If objArgs.count <> 3 Then Wscript.Echo "USAGE: SendCollMail.vbs [CollectionName] [Server] [SiteCode] " Wscript.Echo "" Wscript.Echo " Pull user information for a collection" Wscript.Echo "" Wscript.Quit 1 End If ' Place custom class and column where UserID's can be retrieved here strSMSIdentityClass = "SMS_G_System_CUSTOMCLASS" strSMSIdentityColumn = "UserID" ' Assign arguments to variables and create WMI connection string CollName = objArgs(0) Server = objArgs(1) SiteCode = objArgs(2) SMSLoc = "winmgmts:\\" + Server + "\root\SMS\site_" + SiteCode ' Get CollectionID for the Collection named in the argument. sQuery = "SELECT CollectionID from SMS_Collection WHERE name = " + CHR(34) + CollName + CHR(34) Set CollectionSet = GetObject(SMSLoc).ExecQuery(sQuery) ' If more or less than one CollectionID is found, stop the process. If CollectionSet.Count <> 1 Then wscript.echo "Query found " & cstr(CollectionSet.Count) & " entries in the collection. Can only work with one. Make collection criteria more or less specific." Wscript.Quit End If ' Assign CollectionID to Variable CollID. For each Collection in CollectionSet CollID = Collection.CollectionID 'wscript.echo "Found Collection ID " & CollID & "." Next ' Get the resourceid and machinename for each member of the collection, sorted by resourceid. sQuery1 = "Select ResourceID, Name from SMS_CM_RES_COLL_" & CollID & " ORDER by ResourceID" Set QuerySet = GetObject(SMSLoc).ExecQuery(sQuery1) 'wscript.echo "Found " & cstr(QuerySet.Count) & " machines in collection " & CollName & "." Count = 0 For each item in QuerySet wscript.echo cstr(item.name) Count = Count + 1 Next