VBScript - Script to export SMS Web report results to a CSV file

THE PROBLEM

You want to automatically run a set of SMS Web reports, but you don't have something like SQL Server Reporting Services installed (which would give you the ability to have people subscribe to reports and have them delivered a bunch of ways).  So, you need the ability to run SMS Web reports unattended and save the results somewhere.  

THE SOLUTION (Get the full code here--> ExportSMSReport.txt <-- rename to .VBS)
(UPDATED 3/24/2008  Made OpenTextFile support unicode so special characters will write to text file properly)
(UPDATED 4/01/2008  Using responseBody instead of ResponseText and saving using ADODB.Stream)

The answer is in the object "Microsoft.XMLHTTP".  We can use that little bugger to simulate an HTTP POST command to the web reporting server and fake it into thinking we've just clicked EXPORT on an SMS web report.  We then capture the CSV that gets returned and save it to a file.  This file could later be emailed or just opened directly and reviewed.

 

Here's a quick example of how to use "Microsoft.XmlHttp"


    Set WshShell = WScript.CreateObject("WScript.Shell")

    strURL =
"http://SMSSERVER/SMSReporting_XXX/Report.asp?ReportID=382&param1=abc"
    strOutFile =
"c:\output.csv"

    'setup an HTTP POST to the report URL
    Set http = CreateObject("Microsoft.XmlHttp")
    http.open "Post", strURL, 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   

 

 So, if you want to automate this process, I'd do the following:

  1. Save the attached ExportSMSReport.vbs to a spot on the computer you want to use as the report scheduler
  2. Create a Scheduled Tasks entry for this script (make sure you pass the reportURL and the name of the output CSV file)
    The command-line for that task should look something like this:
    cscript c:\ExportSMSReport.vbs "http://reportURL/report.asp?ReportID=384" "c:\Reports\Report384.csv"
  3. Schedule this task as a user who has rights to run the report you want exported

At this point whenever the scheduled task gets run, you should get a CSV file with the exported data from the report URL that you specified (make a new scheduled task for each new report you want exported)

(Get the full code here--> ExportSMSReport.txt <-- rename to .VBS)

Syntax:

 cscript c:\ExportSMSReport.vbs "http://ReportServerURL/report.asp?ReportID=384" "c:\Reports\Report384.csv"

I hope you find this useful!

Number2 (John Nelson)
MyITForum - Forum Posts
MyITForum - Blog
Add to Google

 

Published Monday, March 10, 2008 1:01 PM by jnelson

Comments

# VBScript - (UPDATED) Script to export SMS Web report results to an Excel spreadsheet

Wednesday, April 02, 2008 3:58 AM by Number2 Blog - MyITForum.com

BACKGROUND In a previous post I created a VBScript in response to a discussion in the forums where somebody

# re: VBScript - Script to export SMS Web report results to a CSV file

Wednesday, May 14, 2008 6:33 PM by riles01

This was a great and very helpful script. I tried converting it to work with SSRS since I subscribing has been disabled; however, I get the following error:

"The path of the item 'fReportCurrent' is not valid. The full path must be less than 260 characters long, must start with slash; other restrictions apply. Check the documentation for complete set of restrictions. (rsInvalidItemPath) Get Online Help"

If I just type in the url, I can get the report just fine, but I have to click OK to save the file. Is that the part that's missing? I can't find anything else on this issue.

Thanks!

# re: VBScript - Script to export SMS Web report results to a CSV file

Thursday, May 15, 2008 12:16 AM by jnelson

Hmm, well I just don't know about that.  I only wrote this to solve the SMS web report problem to mimic the subscribing in SSRS.  I haven't looked into the way SSRS is doing it's posts and responses to know if it's similar enough to do the same thing with it.  But if you have SSRS, then why would you have SSRS disabled?  That's one of the great benefits!  You've got the power to subscribe to reports right there, so use it! (I'm betting it's something political.

# re: VBScript - Script to export SMS Web report results to a CSV file

Tuesday, June 24, 2008 2:54 AM by nihar

Hi,

But didn't succeed to schedule a SMS report to automate running/exporting data in .CSV format and getting a "access denied" error. I think it may be due to some authentication issue with my account.

In this Link, "myitforum.com/.../ExportSMSReport.txt", I found some prerequisites for automating the task of running/exporting a SMS Report to .CSV file.

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.'

Please suggests what are the permissions required to perform these tasks... Please help me...

# re: VBScript - Script to export SMS Web report results to a CSV file

Tuesday, June 24, 2008 10:33 AM by jnelson

Well, are you getting access denied running it manually yourself or only when you schedule it via scheduled tasks?  I'd say first make sure your user account has rights to run a normal report on the server.  Then make sure it has rights to run this modified asp on the same server.  If all that works, then use the same account to schedule a report to be run to see if it's the user permissions or something else.  If the account doesn't have rights to output to the file or folder you passed to it, that won't work either.  So I guess, what's giving you the error?  Can you post it?

Powered by Community Server (Commercial Edition), by Telligent Systems