$i = 0;
while($i -lt 100)
{
$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri '__echange__uri__' -Authentication Kerberos
Import-PSSession $s
Get-Module | where { $_.Name -match "tmp" } | Remove-Module
Get-PSSession | Remove-PSSession
$i = $i + 1
}
After executing the foregoing script, powershell runtime takes more than 3.5 GB of memory and I am unable to free this memory otherwise than by killing the whole process. I am suspecting that it has something to do with Import-PSSession command, probably a memory leak occurs. Is there a way to free memory alocated by Import-PSSession/New-PSSession without killing the powershell.exe process?
I use Powershell v3.0.