Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 7

PowerShell fileage

I have a PowerShell script below that checks for  file age and sends an alert when the condition is reached. The script works when I run it on the Node. I have other alerts configured for the Node. I just don;t seem to understand how to get or pass the the information from the script to Orion to alert on.


I appreaciate your assistance



$path = 'c:\temp'
$stats = 0
$msg = ''
$days = 3
$hours = 10
$mins = 5

$files = @(Get-ChildItem -Recurse -Path $path -Include '*.*' | ?{ $_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$mins) -and $_.psIsContainer -eq $false})

if ($files -ne $null) {
$f_names = [System.String]::Join('|',$files)
$msg = 'Message: ' + $f_names
$stats = $files.Count
} else {
$msg = 'Message: 0 files exceed defined age'

Write-Host $msg
Write-Host "Statistic: $stats"

0 Kudos
1 Reply
Level 13

I believe to return data, you need to send back a specially formatted output string for each metric. Each metric basically needs a unique "tag" string for it as you can send back multiple metrics. I put this output at teh bottom of my script and try to make sure (with lots of error handling) it is the ONLY output of the script. I also Exit(0) to give it a successful exit at the end, and a Exit(1) if I encounter an error in the script I cannot recover from as I believe this causes Orion to indicate the script is failing ( a grey or red icon/status. I'm not sure anymore)

Example: Using your variables and a "metric" tag string of "ThisIsTheUniqueMetricTag"

# Send the data back to Orion
write-host "Message.ThisIsTheUniqueMetricTag: The message is $($msg)"
write-host "Statistic.ThisIsTheUniqueMetricTag: $($stats)"

Exit (0)