$Machines = Get-Content Machines.txt
foreach($Machine in $Machines)
{
$session = New-PSSession -ComputerName $Machine -Credential $creds
Invoke-Command -ComputerName $Machine -ScriptBlock {
#Download
& 'wget' 'http://software/software.7z'
#Extract
& '7z' 'x' 'C:\software.7z' '-r' '-y'
$cleanscript = "Remove-Item C:\software.7z -Force"
$cleanscript | Out-File C:\RemoveZip.ps1 -Encoding ascii
& "C:\RemoveZip.ps1"
$script = "CALL C:\software\setup.exe"
$script | Out-File C:\software.cmd -Encoding ascii
& "C:\software.cmd"
} -Credential $creds
}
After running through 30 machines, PowerShell and the machine running the script runs out of memory. How can this be avoided?
The shell consumes all 16 GBs of memory on running machine. Solutions like exceeding memory for the shell may not work e.g. OutOfMemory Exception on remote execution using Powershell Invoke-Command