Four Methods to Configure Maximum PowerShell Memory in Windows Server
Fine-Tuning PowerShell for Enhanced Performance: Configuring MaxMemoryPerShellMB in Windows Server


Introduction
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:
- Open a PowerShell command line interface.
- 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
- Locate the
MaxMemoryPerShellMB
setting in the configuration. It should be displayed along with its current value. - 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:
- Open a PowerShell command line interface.
- To check the current value of MaxMemoryPerShellMB, use the following command:
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
- 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
Certifications
Video Course
Printed Book
eBooks
Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Ansible Cookbook: A Comprehensive Guide to Unleashing the Power of Ansible via Best Practices, Troubleshooting, and Linting Rules with Luca Berton
Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
Ansible Automation Platform By Example: A step-by-step guide for the most common user scenarios
Method 3: Using Batch Command
Configuring MaxMemoryPerShellMB can also be achieved using a batch command. Follow these steps:
- Open a Command Prompt (CMD).
- 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:
- Open a Command Prompt (CMD).
- 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.
Conclusion
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, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.Academy
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
Donate
Want to keep this project going? Please donate