'==================== ' ExportSMSReport.vbs (rename to .VBS if it's saved as .TXT) ' ' Author: John W. Nelson (Number2) http://www.number2blog.com ' Description: This script takes 2 arguments (SMS report URL and an output fileName) It will execute the ' said SMS report (and act as if you clicked the EXPORT button on the top of the report) ' and dump a comma-delimited list of the report data into said CSV file. It is intended to ' facilitate the automatic running/exporting of reports using the Windows task scheduler. ' ' Requirements: Ability to run vbscript using CSCRIPT ' Access to "Microsoft.XmlHttp" which I believe is part of MSXML and thus IE. ' Access to "ADODB.Stream" for saving the binary output properly ' An account with rights to run SMS Web reports ' Ability to write a CSV file to a folder on the machine running this script. ' ' Disclaimer: As always, this script is released as-is with no warranty for any particular purpose. ' Test the script before attempting to run on any production systems. It has only been tested ' on my personal workstation (Server 2003 x64) using the web reports on an SMS 2003 SP3 server. ' I'm sure there are some kinds of limitations related to report response size. I've only ever ' tried with reports that return up to 1.6MB of data. Any limitation would be in the recieve ' buffer limit of "Microsoft.XmlHttp" (whos limitations I can't find documented anywhere) '================================================================================================================= ' exportSMSReport(strReportURL) ' ' Syntax: exportSMSReport("http://reporturl?param=value","c:\OutFile.csv") Function exportSMSReport(strReportURL,strOutputFile) 'On Error Resume Next Set WshShell = WScript.CreateObject("WScript.Shell") 'setup an HTTP POST to the report URL Set http = CreateObject("Microsoft.XmlHttp") http.open "Post", strReportURL, False http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 'required header 'fake SMS into thinking EXPORT has been clicked. The following line initiates the POST http.send "export=yes" 'save binary response using ADODB.Stream Set oStream = createobject("ADODB.Stream") oStream.type = 1 'adTypeBinary oStream.open oStream.write http.responseBody 'write the binary response from our POST above to the stream oStream.savetofile strOutputFile, 2 '2=adSaveCreateOverwrite...save http stream to a file oStream.Close Set WshShell = Nothing End Function '================================================================================================================= If (WScript.Arguments.Count = 2) Then ReportURL = WScript.Arguments(0) 'example "http://SMSSERVER/SMSReporting_XXX/Report.asp?ReportID=382¶m1=abc" OutFile = WScript.Arguments(1) 'example: "c:\output.csv" exportSMSReport ReportURL,OutFile Else WScript.Echo "SYNTAX: CSCRIPT ExportSMSReport.vbs ""reportURL"" ""OutputFile.csv"" " End If