0
Problem found on server with Powershell v 4.0 (server with Powershell 5.1 they do not seem affected by the same problem)
This a strange behavior of Invoke-WebRequest command.
Take this example:
For some reason, I need to know the file size before download it on my server.
Then I use the following commands:
$WebClient = Invoke-WebRequest -Uri $element -Method Head -Credential $Cred
$filesize = $webClient.Headers.'Content-Length'
The problem is before send $WebClient request Powershell use (for Commit RAM) about 120MB, but after the request powershell enlarge your RAM a the file $filesize value (example remote file is 800MB, new Commit RAM is 920MB).
When you work with Powershell WinRM session limited at 1GB of RAM this can be a problem. (OOM)
If you send and HEAD request, and the remote system know the Content-Lenght of the resource request, Powershell (and all other language) not receive the file, but only a the HEAD with the Content-Lenght inside. So, I guess, it makes no sense to allocate as much memory as the file is large if I only do a head request. – Max Monterumisi – 2018-12-05T13:40:37.283
Actually you are right and there is a way using
Invoke-WebRequest
. I rewrote my answer. – harrymc – 2018-12-05T13:52:22.310