I have a script that does the following:
$DirectoryPathFileCount = Get-ChildItem -Path $DirectoryPath | Measure-Object
If ($DirectoryPathFileCount.count -eq 0) {
Write-Output "No files in directory path $DirectoryPath"
LogWrite "No files in directory path $DirectoryPath"
}
Else {
Write-Output "Number of files in $DirectoryPath is $($DirectoryPathFileCount.count)"
LogWrite "Number of files in $DirectoryPath is $($DirectoryPathFileCount.count)"
LogWrite is a function that writes to a log file, and the $DirectoryPath is c:\temp. I have tried this script switching the order of the Write-Output and the LogWrite and it has not made a difference.
I have one file in this directory. I created a VisualCron job that runs every 20 seconds with one task that calls this script. In the Execute tab Command = powershell.exe, and the argument is the path and name of the script. When the task runs, the non-VisualCron log file is correctly written to 100% of the time. The VisualCron task Output(standard) about 95% of the time will correctly show this:
Number of files in c:\temp is 1
The problem is I cannot figure out why sometimes the Output(standard) is "No output". There is nothing there. The execution time for this task is usually less than one second. I have noticed that when this problem occurs, the execution time is long -- anywhere from 4 to 40 seconds. Sometimes the execution time is between 20-40 seconds and the output does exist, but there is a correlation between a long execution time and a higher probability that there is no output.
Ideas?
Edited by user
2021-06-09T22:19:50Z
|
Reason: Not specified