As there is no possibility of saving a Report as csv file on schedule in ITMS 7.x, here's a powershell script to do so.
- Create a new 'Run Script on Server' Task, choose 'Powershell' and paste the code below.
- Replace the variables.
- $reportGUID: Guid of the Report you want to run
- $reportFile: Path and file name of the output file. Either use a local path on the NS, where the script runs, or use a network directory. Make sure that the application identity of your Notification Server has the required rights to delete and write files in this directory.
- $separator: Depending on your location, use comma or semicolon as separator in the csv file.
- Also replace the connection credentials of ASDK.
- Set a schedule for the script.
You can also add a 'Send email' Task where you send the report file link (attachment is not possible) to some administrators or whatever. Then put both tasks in a Job to schedule.
# Save Report as CSV
#######################################
# HauckS
# 2015-10-02
#
# Change History:
#######################################
# Declare Variables
$reportGUID = "a36f2aef-4758-4b2b-a7a1-bafe2d28dca5";
$reportFile = "\\%NSSERVER%\share\Export\report.csv";
$separator = ";" # Comma or Semicolon
try
{
# Load ASDK Object
$oReportManagement = New-Object -Com Altiris.ASDK.NS.ReportManagement;
# Connect to Server
$oReportManagement.TargetServer = "%NSSERVER%";
$oReportManagement.UserName = "userxy";
$oReportManagement.Password = "passwordxy";
$oReportManagement.Authenticate();
# Get Report
$reportResult = $oReportManagement.RunReport($reportGUID);
# Create File
if(Test-Path $reportFile)
{
Remove-Item $reportFile;
}
New-Item -Type file -path $reportFile;
# Create StreamWriter
$writer = [System.IO.StreamWriter] $reportFile;
# Process Recordset
if($reportResult.RecordCount -gt 0)
{
$reportResult.MoveFirst();
# Write Field Names
$line = $reportResult.Fields.Item(0).Name;
for($i=1; $i -lt $reportResult.Fields.Count; $i++)
{
$line = $line + $separator + $reportResult.Fields.Item($i).Name;
}
$writer.WriteLine($line);
# Process every line in Report
do
{
$line = $reportResult.Fields.Item(0).Value;
for($i=1; $i -lt $reportResult.Fields.Count; $i++)
{
$line = $line + $separator + $reportResult.Fields.Item($i).Value;
}
$writer.WriteLine($line);
$reportResult.MoveNext();
}
until($reportResult.EOF);
}
# Close StreamWriter
$writer.close();
}
catch{
echo $error;
exit;
}
About the script:
- I developed and tested it on ITMS 7.5 SP1 HF1.
- To process a custom Report with 8 columns and 50.000 rows, the script needs about 3 minutes to run.
- No extras, no features, just plain report-to-file. If you need some more, you can ask me.