获得大约 150MB shell 功率限制shell

Getting around 150MB shell limit in powershell

发自 https://serverfault.com/questions/752202/install-net-4-6-1-remotely-via-powershell

基本上我在尝试 install/run .NET Framework 升级时遇到了各种错误,因为 powershell 会话内存不足。尝试通过 Chocolatey 安装时,出现 'Thread cannot start' 问题。通过标准 powershell 尝试,exe 似乎 'bomb out' on iex 因为提取器占用了太多内存。我也试过 Start-Processiex("cmd.exe /C pathtoexe.exe") 但也失败了。

我无法登录所有 N 台主机并更改其 powershell 限制,如下所示:http://blogs.technet.com/b/heyscriptingguy/archive/2013/07/30/learn-how-to-configure-powershell-memory.aspx 因为我有大量主机。希望社区有一些想法。下面的脚本

    Write-Host "Executing 'Upgrade dotnet 4.6' for $server"
    Invoke-Command -ComputerName $servers -Credential $credentials -ScriptBlock {
    $Url = 'https://download.microsoft.com/download/E/4/1/E4173890-A24A-4936-9FC9-AF930FE3FA40/NDP461-KB3102436-x86-x64-AllOS-ENU.exe'
    $Exe = "net461.exe"
    $Dest = "C:\" + $Exe
    $Params = " /q"
    $client = new-object System.Net.WebClient
    $client.DownloadFile($Url,$Dest) 
    Invoke-Expression ("cmd.exe /C " + $Dest + $Params)
    } 

以下 Powershell 将允许绕过 150 MB 限制(将其设置为无限制)

Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Client -Name MaxMemoryPerShellMB -Value 0 -Type DWord
Restart-Service winrm