Click an Ad

If you find this blog helpful, please support me by clicking an ad!

Friday, June 14, 2013

Running Scheduled Reports in Spiceworks

We love Spiceworks! BUT it's still missing some things. One of which is the ability to set up reports to run automatically and email them to you. Well, it's not missing per se, it's just kind of complicated. The ability is there, and this is how to use it.

The post here within the Spiceworks Community got me started, but I wanted to show the whole picture.

  1. On your Spiceworks server, go to c:\Program Files (x86)\Spiceworks and create a new folder called 'rpt'.
  2. Now go into c:\Program Files (x86)\Spiceworks\pkg\gems\spiceworks-X.X.XXXXX (where the X's represent your version number), and copy the file run_report.rb into the rpt folder you created in step 1.
  3. Open a command prompt and navigate to c:\Program Files (x86)\Spiceworks\rpt and execute the following command to see how to use this ruby script:
    ..\bin\ruby run_report.rb -?
  4. Now, you need to find the report number that corresponds to the report you want to run. In my case, I used the following command:
    ..\bin\ruby run_report.rb -e user@contoso.com -p password -l 
  5. Your Spiceworks login credentials are used in the above command, as well as -l, which lists all reports, along with their report numbers. Write down the report numbers you want.
  6. In a batch file, write a line for each report. Here is an altered copy of my batch file:

    cd "C:\Program Files (x86)\Spiceworks\rpt"

    REM To get a list of tickets run this command:
    REM ..\bin\ruby run_report.rb -e user@contoso.com -p password -f pdf -l

    REM Run Report #72
    ..\bin\ruby run_report.rb -e user@contoso.com -p password -f pdf 72

    REM Run Report #73
    ..\bin\ruby run_report.rb -e user@contoso.com -p password -f pdf 73

    REM Run Report #74
    ..\bin\ruby run_report.rb -e user@contoso.com -p password -f pdf 74

    powershell.exe -NoProfile -File C:\ps\SpiceworksReporting.ps1


  7. Pay attention to the last line, which calls a powershell script that will email you the reports! Here's that file:

    #This file is run at the tail-end of SpiceworksReporting.bat

    $To = "admin@contoso.com"
    $From = "spiceworks@contoso.com"
    $Subject = "Spiceworks Reports"
    $SMTPServer = "smtpserver.contoso.com"
    $Body = "See Attached File(s)"

    #Report 1: 
    $file1 = "C:\Program Files (x86)\Spiceworks\rpt\report-72.pdf"

    #Report 2:
    $file2 = "C:\Program Files (x86)\Spiceworks\rpt\report-73.pdf"

    #Report 3:
    $file3 = "C:\Program Files (x86)\Spiceworks\rpt\report-78.pdf"

    #Send Email
    Send-MailMessage -To $To -From $From -SMTPServer $SMTPServer -Subject $Subject -Body $Body -Attachments $file1,$file2, $file3

    Remove-Item $file1
    Remove-Item $file2
    Remove-Item $file3


  8. Now, go into Task Scheduler and create a task to run the batch file. The batch file creates the reports, which output into pdf and are stored in the rpt folder we create. Then, the batch file calls the Powershell script which emails these files as attachments and then deletes the PDF files that were created.
Voila! You have automated Spiceworks reports!

2 comments:

  1. I have everything down, I am creating the task, when locating the program to run, I found the batch file. I chose it. but when "RUNNING" the task, does nothing?

    Please contact me at Sou.Moua@gopherelectronics.com

    ReplyDelete
  2. I had some issues getting Powershell scripts to run as scheduled tasks as well. I was never able to figure out why, so what I ended up doing was making a domain admin account that runs all of my scripts. That worked. If you find out why, let me know please.

    ReplyDelete