Child job output showing up in parent job log multiple times

Product: PowerShell Universal
Version: 5.2.0

Hello!

I have a script that invokes other PSU scripts, which successfully create child jobs underneath the parent job when run. All of the scripts use “Write-Output” to log to the console. The problem is that when viewing the log in the parent job, the “Write-Output” messages from the child scripts are shown as well. And not only are they shown, but the outputs are sometimes repeated multiple times in the log (2 to 10 times on new lines, at random). It results in a very messy parent log.

All of the output looks normal when viewing the child jobs individually, this is only when viewing the parent job’s log. My concern is that not only does it make the parent job log largely unreadable, but there may also be performance issues with so much log output.

Is there any option or cmdlet or way to ensure that the child job output does not show up in the parent job’s log? I would love to keep them separate. And if not, why is the output being repeated so many times?

Has anyone else experienced this? Any insight is greatly appreciated!

The reason you are seeing duplicates is that, when using Write-Output, you are seeing both the pipeline output and the informational stream.

First, I would recommend change it to Write-Host (WinPS) or Write-Information (PS7) if you are using Write-Output to just write strings. This will speed your jobs up and keep your database much smaller. Using Write-Output for strings causes them to be serialized to CliXml and stored in the database. It will grow quickly this way.

Next, I would recommend using -Silent on Invoke-PSUScript in the parent job. This will prevent PSU from sending the child job’s output streams to the parent job. This will clean up the parent job and greatly reduce the size of the job logs in the database.

Invoke-PSUScript -Name 'Child.ps1' -Silent

If you want a little control over what the child job writes to the parent job, you can also use the preference variables (e.g. $InformationPreference) to limit what Invoke-PSUScript sends to the parent.

I made both of the changes you suggested and got what I was looking for. Thank you Adam!!

Is there any way to reclaim the space taken up by all of the jobs utilizing “Write-Output”? Will archiving them help?

Archiving won’t help but those previous jobs will be groomed away after 30 days or after the scripts you are running have a history of 100 (by default).

1 Like