Ansible Pilot

Four Methods to Configure Maximum PowerShell Memory in Windows Server

Fine-Tuning PowerShell for Enhanced Performance: Configuring MaxMemoryPerShellMB in Windows Server

October 30, 2023
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons


Windows Server administrators often need to configure various parameters to optimize PowerShell session performance and resource allocation. One such critical parameter is the MaxMemoryPerShellMB, which determines the maximum memory allocated to each PowerShell session. This article will explore multiple methods to configure the MaxMemoryPerShellMB setting.

Method 1: Using PowerShell Command Line Interface

The most straightforward way to configure MaxMemoryPerShellMB is through PowerShell itself. Follow these steps:

  1. Open a PowerShell command line interface.
  2. Navigate to the WSMan Shell configuration by using the sl (Set-Location) and dir (Get-Item) commands:
PS C:\> sl WSMan:\localhost\Shell 
PS WSMan:\localhost\Shell> dir
  1. Locate the MaxMemoryPerShellMB setting in the configuration. It should be displayed along with its current value.
  2. To set a new value, use the Set-Item command:
PS WSMan:\localhost\Shell> Set-Item .\MaxMemoryPerShellMB 1024

This method allows for precise control of the MaxMemoryPerShellMB setting.

Method 2: Using PowerCLI Commands

If you prefer to use PowerCLI commands for configuring PowerShell memory, here’s how to do it:

  1. Open a PowerShell command line interface.
  2. To check the current value of MaxMemoryPerShellMB, use the following command:
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
  1. To set a new value, use the Set-Item command as shown below:
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024

These PowerCLI commands provide an alternative way to configure the MaxMemoryPerShellMB setting with a more PowerShell-centric approach.

The Best Resources For Ansible


Video Course

Printed Book


Method 3: Using Batch Command

Configuring MaxMemoryPerShellMB can also be achieved using a batch command. Follow these steps:

  1. Open a Command Prompt (CMD).
  2. Run the following command to configure MaxMemoryPerShellMB:
winrm.cmd set winrm/config/winrs @{MaxMemoryPerShellMB="1024"}

This method is useful if you prefer to work with batch scripts or are in an environment where batch commands are more prevalent.

Method 4: Configuring Multiple Machines Remotely

If you need to configure MaxMemoryPerShellMB on multiple machines remotely, you can use a batch command as well. Here’s how:

  1. Open a Command Prompt (CMD).
  2. Run the following command, assuming you have a list of target servers in a file named servers.txt:
for /f %%i in (servers.txt) do ( 
echo %%i
psexec \\%%i -s winrm.cmd quickconfig -q
psexec \\%%i -s winrm.cmd set winrm/config/winrs @{MaxMemoryPerShellMB="512"}

This command will configure MaxMemoryPerShellMB on all the servers listed in servers.txt remotely.


In conclusion, configuring the MaxMemoryPerShellMB setting is essential for managing PowerShell sessions efficiently, and you can choose the method that best suits your requirements and environment. Whether you prefer PowerShell, PowerCLI, batch commands, or remote configurations, these methods provide flexibility and control over your Windows Server PowerShell sessions.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.


Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases