Ying Li at myITforum.com

PowerShell & System Center

Powershell script to change 'MaximumQueueSizeKb' registry value on multiple servers.

In our SCOM 2007 environment, we get a lot of the below alert:

Alert: Alert generated by Send Queue % Used Threshold

Source: xyz.related.com

Path: xyz.related.com

Last modified by: System

Last modified time: 5/22/2008 6:29:13 PM Alert description: The current value of 60.2739067077637 is outside the accepted threshold

 

Alert view link: "http://whatever:51908/default.aspx?DisplayMode=Pivot&AlertID={d815369d-b5f9-4b03-a572-fa9857e781af}"

Notification subscription ID generating this message: {4B6F3971-955E-1491-6D82-5C22F1466FC2}

 

Stefan Stranger has a Blog about this. He mentioned that we need to increase the size of the following registry key:

 

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HealthService\Parameters\Management Groups\%Management Groupname%\MaximumQueueSizeKb]

 

Which I have been using to fix the alert and for some server, I even go one step further changing the size to 61440. But I kind tired of doing this on each server – the solution is PowerShell and remote registry!

 

Mow has a blog about using PowerShell to change the remote registry key.

 

Enlighten by their work, I come up with the below script to use PowerShell changing registry key on multiple remote server and report in excel:


$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)


$c.Cells.Item(1,1) = "Server Name"
$c.Cells.Item(1,2) = "Old MaximumQueueSizeKb"
$c.Cells.Item(1,3) = "New MaximumQueueSizeKb"
$c.Cells.Item(1,4) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = get-content C:\MachineList.txt
foreach ($strComputer in $colComputers)
{
$c.Cells.Item($intRow,1)  = $strComputer.Toupper()

Function GetRegInfo
{
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strComputer)
$key="SYSTEM\CurrentControlSet\Services\HealthService\Parameters\Management Groups\XYZ Enterprise Apps"
$regKey = $reg.OpenSubKey($key)
$max = $regkey.GetValue("MaximumQueueSizeKb")

If($max -eq '15360')
{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 3
$c.Cells.Item($intRow,2) = $max

#$True make the registry key writable
$regKey = $reg.OpenSubKey($key, $True)
$regkey.SetValue('MaximumQueueSizeKb', 30720)
$newmax =  $regkey.GetValue("MaximumQueueSizeKb")

$c.Cells.Item($intRow,2) = $newmax
}
Else
{$c.Cells.Item($intRow,2) = $max}

}
GetRegInfo

$c.Cells.Item($intRow,4) = Get-date
 
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls

 
Happy PowerShelling and Sharing!

 

Comments

No Comments