The post here within the Spiceworks Community got me started, but I wanted to show the whole picture.
- On your Spiceworks server, go to c:\Program Files (x86)\Spiceworks and create a new folder called 'rpt'.
- 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.
- 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 -?
- 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 email@example.com -p password -l
- 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.
- 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 firstname.lastname@example.org -p password -f pdf -l
REM Run Report #72
..\bin\ruby run_report.rb -e email@example.com -p password -f pdf 72
REM Run Report #73
..\bin\ruby run_report.rb -e firstname.lastname@example.org -p password -f pdf 73
REM Run Report #74
..\bin\ruby run_report.rb -e email@example.com -p password -f pdf 74
powershell.exe -NoProfile -File C:\ps\SpiceworksReporting.ps1
- 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 = "firstname.lastname@example.org"
$From = "email@example.com"
$Subject = "Spiceworks Reports"
$SMTPServer = "smtpserver.contoso.com"
$Body = "See Attached File(s)"
$file1 = "C:\Program Files (x86)\Spiceworks\rpt\report-72.pdf"
$file2 = "C:\Program Files (x86)\Spiceworks\rpt\report-73.pdf"
$file3 = "C:\Program Files (x86)\Spiceworks\rpt\report-78.pdf"
Send-MailMessage -To $To -From $From -SMTPServer $SMTPServer -Subject $Subject -Body $Body -Attachments $file1,$file2, $file3
- 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!