-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathSet-PowerShellMemoryTuning.ps1
50 lines (37 loc) · 1.7 KB
/
Set-PowerShellMemoryTuning.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function Set-PowerShellMemoryTuning{
param(
[parameter(
position = 0,
mandatory = 1)]
[ValidateNotNullorEmpty()]
[ValidateRange(1,2147483647)]
[int]
$memory
)
# Test Elevated or not
$TestElevated = {
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if (&$TestElevated)
{
# Machine Wide Memory Tuning
Write-Warning "Current Memory for Machine wide is : $((Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB).value) MB"
Write-Warning "Change Memory for Machine wide to : $memory MB"
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB $memory
# EndPoing Memory Tuning
Write-Warning "Current Memory for Plugin is : $((Get-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell).value) MB"
Write-Warning "Change Memory for Plugin to : $memory MB"
Set-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell $memory
# Restart WinRM
Write-Warning "Restarting WinRM"
Restart-Service WinRM -Force -PassThru
# Show Current parameters
Write-Warning "Current Memory for Machine wide is : $((Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB).value) MB"
Write-Warning "Current Memory for Plugin is : $((Get-Item WSMan:localhost\Plugin\microsoft.powershell\Quotas\MaxConcurrentCommandsPerShell).value) MB"
}
else
{
Write-Error "This Cmdlet requires Admin right. Please Elevate and try again."
}
}