Task running PowerShell script periodically has "no output" - VisualCron - Forum

Community forum

Scott Kemmeries
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.
Task Output with periodic No output.png
Danny van Oijen

Sometimes Powershell can be a bit slow, especially when starting PowerShell.
Why not use the build in tasks vCron has? (Add Job File --> List Files) this is very fast.
Scott Kemmeries
List Files will not just give me a count of the number of files, which is what we need. Regardless, why would PowerShell being slow result in No output? Often when it is slow we still get output.
Danny van Oijen

The List Files has a result variable called Number of listed files.
This counts the files that are present.
Scott Kemmeries
Yes, I see I can use {TASK(Active|Result.NoFiles)}, so I have a workaround. (And thank you.) Still, the question I'm trying to answer is, if I run the same job and task running the same PowerShell script repeatedly, why is there sometimes No output?

If this a known VisualCron bug that occurs when "Powershell can be a bit slow, especially when starting PowerShell"? And if so, is the problem with PowerShell being slow sometimes also a bug?
Danny van Oijen

No powershell works ok but starting the powershell console is a bit slower.

Just start powershell on the server where you want to start the script.
You can see it takes 1 á 2 seconds before it is started, this is normal behavior (not related to visualcron) but when running this in a loop for let's say 500 times than it is slow compared to the build-in features visualcron has.

Why it gives no output i don't know.
Scroll to Top