Author Posts

June 6, 2018 at 8:08 pm

Hello, I have noticed some strange behavior with Powershell when run in a remote session, it seems as if there is a memory leak with write-progress when run in a remote session. Is there something I need to do to manually clear this up? I am running Powershell version 5 on both the calling pc and the target.

Take the following code for example:

$MaxVal = 10000000

for ($x=1;$x -le $MaxVal;$x++)
{
    Write-Progress -Activity "Writing a progress event" -PercentComplete ($x / $MaxVal * 100) -Status "$($x / $MaxVal * 100)% complete"
}

If I run this locally, powershell.exe runs normally and does not take up much memory.

However, if I run it on the same computer from a remote session (as in, I do an enter-psesssion -computername computer).

The memory on powershell.exe keeps going up until it eventually crashes the process.

Is there something I am doing wrong or is this a bug within powershell? I noticed it because I have a long running script that I use write-progress in and it was running fine whenever it runs locally, but calling it in a powershell session kept hanging the script and it would never complete. If I just remove all the calls to write-progress from the script, it runs fine in a remote session.

June 7, 2018 at 8:29 pm

You could certainly open an issue on Write-Progress in the PowerShell GitHub repo.