Windows 10(およびWindows Server 2012, 2012 R2, 2016, 2019も同じ)でのPowershellの実行時の最大メモリ数の変更手順。Powershellを実行したときに、メモリを使いすぎたので、制限する。
変更手順
- Powershellを管理者モードで起動する
- Powershellのバージョン確認する
$PSversionTable
※Powershellが3.0以降の場合は、追加手順あり。 - Powershellのメモリ割り当てサイズの確認
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB - 設定変更
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048 - プラグインの確認(Ver3.0以降の場合は実行)
ls WSMan:localhost\Plugin - プラグインのPowershellの割り当てサイズの確認(Ver3.0以降の場合は実行)
Get-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell - プラグインのPowershellの割り当てサイズの変更(Ver3.0以降の場合は実行)
Set-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell 2048 - 設定変更後WinRMの再起動
Restart-Service WinRM - 事後確認
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB - 32bitのPowershellを管理者モードで起動する
- Powershellのメモリ割り当てサイズの確認
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
※もし、32bitのPowershellのメモリが変わっていない場合は、同じように変更する。
作業ログ。
PS C:\WINDOWS\system32> Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Shell
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String MaxMemoryPerShellMB 2048
PS C:\WINDOWS\system32> Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048
警告: 更新された構成は、プラグインあたりのクォータの値が 2048
を超えるプラグインの操作に影響する可能性があります。登録されているすべてのプラグインの構成を確認し、影響を受けるプラグ
インのプラグインあたりのクォータの値を変更してください。
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> ls WSMan:localhost\Plugin
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin
Type Keys Name
---- ---- ----
Container {Name=Event Forwarding Plugin} Event Forwarding Plugin
Container {Name=microsoft.powershell} microsoft.powershell
Container {Name=microsoft.powershell.workf... microsoft.powershell.workflow
Container {Name=microsoft.powershell32} microsoft.powershell32
Container {Name=WMI Provider} WMI Provider
PS C:\WINDOWS\system32> Get-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin\microsoft.powershell\Quotas
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String MaxConcurrentCommandsPerShell 2147483647
PS C:\WINDOWS\system32> Set-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell 2048
警告: 構成の変更は、WinRM サービスを再起動しないと有効になりません。WinRM
サービスを再起動するには次のコマンドを実行します: 'Restart-Service winrm'
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> Restart-Service winrm
PS C:\WINDOWS\system32>