I am using a slightly modified Windows Powershell component monitor to find files that should be newer then some number of minutes since current time. The files are on a cif share so I have the template deployed to one of my pollers and the path to the file is a unc. On the poller the script returns the expected output when run from the PS command line of the poller but, when I run it via "Edit Script" to produce the outputs or I run it as a test of the component, it does not return the expected result. I have it set to run on localhost which is the poller where I've deployed it. I expect to find 1 file newer then 60 minutes. But it says 0 files newer then 60 minutes. Why? Where is it looking
Inputs
\\mucifshare\Departments\*.dae, 60
Script
param([string]$path, [int]$minutes)
# Created by Thwack user Chad.Every. See https://thwack.solarwinds.com/docs/DOC-190598 for more detail.
# Pass in the directory path including a * with the extension type you want to check. Then pass in the number of minutes old that file needs to be.
#Example, change this path to the folder/file type you wish to monitor. Wildcard in file name and extension are supported.
#$path="c:\temp\*.txt"
$stat=0
$msg=""
try
{
$LastWrite = $(Get-Date).AddMinutes(-$minutes)
$FileArray = $(Get-ChildItem $path | Where-Object { !$_.PSIsContainer -and $_.CreationTime -gt $LastWrite })
if (($FileArray | Measure-Object).count = "0")
{
$msg = "No file found over $($minutes) minutes old"
}
else
{
$stat=$FileArray.Count
$msg = "$($stat) files found older than $($minutes) minutes: "
foreach ($file in $FileArray)
{
$msg+=" " + $file + ","
}
}
}
catch
{
$stat=1
$msg=$_.Exception.Message
}
Write-Host "Statistic: $stat"
Write-Host "Message: $msg"
exit 0