Sample Header Ad - 728x90

Opening powershell remote sessions in a loop in linux leaks memory

3 votes
0 answers
219 views
I am stuck with the following problem: we have an app that runs an continuous loop opening remote connection via powershell (performing some actions and then closing). This works fine in a Windows machine but not in Linux ones (tested on Ubuntu 16.0.4). Use the the script below to reproduce the problem: $i = 0 while ($i -le 200) { $password = "myPassword" $domain = "domain\computerName" $computerName = "xxx.xxx.xxx.xxx" $pwSession = convertto-securestring -AsPlainText -Force $password $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $domain,$pwSession $session = new-pssession -computername $computerName -credential $cred -Authentication Negotiate Remove-PSSession -Session $session Get-PSSession sleep 3 $i $i++ } 1. enter a powershell context by running pwsh 2. run the script above (copy + paste) 3. run top -p {process id} on the pwsh process id (you can run it in a single step with top -p $(ps -aux | grep pwsh | head -n 1 | cut -d' ' -f5) You will see a window like enter image description here You will notice the memory consumption will keep growing (by 0.1 percent at each iteration), indefinitely. Google does return a couple of posts mentioning memory leaks in opening new sessions with powershell, but I could not find in any of them an explanation on why the simple script above would create such an issue - again, in linux, only. Any ideas in how tackle this issue ?
Asked by Veverke (378 rep)
Apr 12, 2021, 07:18 AM