.PS1 scripts via agent problems

Hello guys,

I'm trying to use some .ps1 scripts on our network (related to Veeam) the results are random, every time.. I don't get why ?

/resized-image/__size/1640x1230/__key/communityserver-discussions-components-files/233/ORION_5F00_job_5F00_succes_5F00_aleatoire.jpg

/resized-image/__size/1640x1230/__key/communityserver-discussions-components-files/233/ORION_5F00_job.jpg

here's the script :

$WarningPreference='silentlycontinue';
$Error.Clear();
$job_name=$args[0];
if ( $job_name -eq $null )
 {
 Write-Host "Message: Can't find ""job_name"" argument. Check documentation."
 exit 1
 }
#try 
 #{ Add-PSSnapin VeeamPSSnapIn; }
#catch
 #{
 #Write-Host "Message: $($Error[0])";
 #exit 1;
 #}
try
 { 
 $job_result=(Get-VBRJob -name $job_name).GetLastResult();
 $job_state=(Get-VBRJob -name $job_name).GetLastState();
 $job_session=(Get-VBRJob -name $job_name).FindLastSession().BackupStats;
 }
catch
 {
 Write-Host "Message: ERROR executing ""Get-VBRJob"". Possibly wrong job name argument. <br/> $($Error[0])";
 exit 0;
 }
switch ($job_result) 
 { 
 "Success" { $stat1=0 } 
 "None" { $stat1=1 } 
 "Failed" { $stat1=2 } 
 default { $stat1=3 }
 }
switch ($job_state) 
 { 
 "Stopped" { $stat2=0 } 
 "Starting" { $stat2=1 } 
 "Working" { $stat2=2 } 
 "Stopping" { $stat2=3 } 
 "Resuming" { $stat2=4 } 
 "Pausing" { $stat2=5 } 
 default { $stat2=6 }
 }
if ( $job_session -eq $null )
 { $stat3=$stat4=$stat5=$stat6=0; }
else
 {
 $stat3=$job_session.BackupSize;
 $stat4=$job_session.CompressRatio;
 $stat5=$job_session.DataSize;
 $stat6=$job_session.DedupRatio;
 }
Write-Host "Message.Last_Job_Result: Last job result: $job_result";
Write-Host "Statistic.Last_Job_Result: $stat1";
Write-Host "Message.Job_State: Job state: $job_state";
Write-Host "Statistic.Job_State: $stat2";
Write-Host "Message.Last_Session_Backup_Size: Backup size in last session: $stat3";
Write-Host "Statistic.Last_Session_Backup_Size: $stat3";
Write-Host "Message.Last_Session_Compression_Ratio: Compression ratio in last session: $stat4";
Write-Host "Statistic.Last_Session_Compression_Ratio: $stat4";
Write-Host "Message.Last_Session_Data_Size: Data size in last session: $stat5";
Write-Host "Statistic.Last_Session_Data_Size: $stat5";
Write-Host "Message.Last_Session_Deduplication_Ratio: Deduplication ratio in last session: $stat6";
Write-Host "Statistic.Last_Session_Deduplication_Ratio: $stat6";
exit 0;

Parents Reply Children
No Data