I have created a Powershell script that monitors a network folder location. The folder is an error folder. The goal is for the script to report back if any new files were placed in the folder in the past hour. The script needs to report back a list of the files and the number of files. I can get it to work and reports back the correct info, but I would like to have the message output formatted with line feeds or carriage returns between each file name.
I know previously that SAM would treat any line feeds as the end of the message and cut out the rest of the text, or ignore carriage returns completely. Is there any workaround solution to this?
Below is the script I am using.
#Input argument is the full network file path to scan
$ErrorActionPreference = "silentlycontinue";
$Error.Clear();
$path = $args.get(0);
$PollPeriod = -1;
$Count = 0;
$Files = "";
$DateToCompare = (Get-Date).AddHours($PollPeriod);
$allfiles = Get-ChildItem -Path $path |
Where-Object {$_.lastwritetime -gt $DateToCompare} |
ForEach-Object {$Count = $Count + 1;$Files += $path + $_.name + [char]13};
If ($Count -eq 0)
{
Write-Host "Message: No new files found";
}
Else
{
Write-Host "Message: $Files";
}
Write-Host "Statistic:" $Count;
Exit 0;