Hi,
I have been working on the following for a few days, as you might guess it runs great in powershell and returns exactly what I would like, but fails to run in SAM with an error.
Here is the script:
$Source = "\\networkshare\data\SolarwindsMonitoring\";
$Destination = "D:\StorSimpleTest";
$results = & cmd /c robocopy $Source $Destination file /np;
$trash = ($results | select-string -Pattern "Mega") -match '\d+\.\d+';
$speed = $Matches[0];
$trash = ($results | select-string -Pattern "Times") -match '\d+\:\d+:\d+';
$time = $Matches[0];
$speed;
$time;
if ( $speed )
{
Write-Host "Message.SpeedSummary: File downloaded at a speed of $speed MB/hour";
Write-Host "Statistic.SpeedSummary: $speed";
Write-Host "Message.TimeSummary: File download time: $time";
Write-Host "Statistic.TimeSummary: $time";
Remove-Item
\StorSimpleTest\file;
Exit 0;
}
Write-Host "Message: $($Error[0])";
Remove-Item
\StorSimpleTest\file;
Exit 1;
And here is the error I get:
Output: ==============================================
Message: Cannot index into a null array.
Errors: ==============================================
Cannot index into a null array.
At line:6 char:1
+ $speed = $Matches[0];
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
I get what the error means, no data in the array because the robocopy fails to run, hence nothing gets placed into the variables. I am just not sure how to modify it to allow solarwinds to kick off the robocopy.