I'm wondering if it's possible to export the results of a SCCM 2007 query via VBScript. If it is any suggestions would be greatly appreciated.
I know I can export reports through SCCM via VBScript by using the web-view of the report and faking the export=yes and submitting the form. Is something like this possible with a query?
Working code as a VBScript function that I ended up with:
'sccmQueryAsArray
'Returns: results in an array built based on the columns specified in the call of the function
' parseInto: an array provided by the calling function that will be filled with the SCCM query results
' sccmSiteServerName: a string representing the sccm site server we are connecting to
' sccmSiteCode: a string representing the sccm site code we are connecting to
' columns: a one dimensional array containing the names of the columns you want to the function to create an array for
' query: the actual full length query that will be passed to WMI object
' example call: sccmQueryAsArray data,"server1","sit",array("Name","UsergroupName"),"select Name, UsergroupName, WindowsNTDomain from sms_r_usergroup where AgentName = 'SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT'"
' results in an array "data" being modified to 2 columns and as many rows as is returned by the query the array would look like:
' (0)(x) where 0 = the first element in the columns row or Name
' (1)(x) where 1 = the second element in the columns row or UsergroupName
function sccmQueryAsArray( ByRef parseInto, ByVal sccmSiteServerName, ByVal sccmSiteCode, ByVal columns, ByVal query )
redim preserve parseInto(ubound(columns),0) 'the array that the query information will be parsed into and then returned
dim objWMIService: set objWMIService = getObject("winmgmts://" & sccmSiteServerName & "\root\sms\site_" & sccmSiteCode) 'set up the connection string
dim colGroups: set colGroups = objWMIService.ExecQuery(query) 'execute the query and put the results into colGroups
dim z: z = 0
dim objGroup: for each objGroup in colGroups
dim y: for y = 0 to ubound(columns) step 1
dim x: x = "objGroup." & columns(y)
parseInto(y,z) = eval(x)
next
redim preserve parseInto(ubound(parseInto,1),ubound(parseInto,2)+1): z = z + 1
next
sccmQueryAsArray = parseInto
end function