Hi,
I need to monitor the age of file in a folder. I can not use the default File Age monitor because it does not accept a wildcard for filename.
The files that are in the folder have different names, hence the need to use another File Age monitoring approach.
I've found a PowerShell script online that does the trick but I am having difficulties getting it to work in SAM. It could be that I don't fully understand what SAM expects as an output.
Hopefully someone here can help so that we all can benefit from it. I know a lot of people have requested the ability to monitor File Age when file does not have a set name.
Here's the PowerShell script:
$fullPath = "C:\hp\hpsmh\certs"
$numdays = 3
$numhours = 10
$nummins = 5
function ShowOldFiles($path, $days, $hours, $mins)
{
$files = @(get-childitem $path -include *.* -recurse | where {($_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$mins)) -and
($_.psIsContainer -eq $false)})
if ($files -ne $NULL)
{
for ($idx = 0; $idx -lt $files.Length; $idx++)
{
$file = $files[$idx]
write-host ("Old: " + $file.Name) -Fore Red
}
}
}
ShowOldFiles $fullPath $numdays $numhours $nummins
Attached screenshots show a test script and the expected output (file name in red). The other screenshot shows the error displayed in SAM when performing a test.
Are there any SAM/PowerShell gurus around that ould modify the script so that it works with SAM?