Check Exchange 2003 vitals with PowerShell

Posted by in Exchange 2003, Exchange Server, PowerShell

I have written recently about Free System PTEs and /PAE usage in Exchange 2003 mailbox servers.

I set out to write a PowerShell script that will run against given list of servers and report back certain vitals including boot.ini settings, SystemPages registry setting and current performance data for Free Sytem PTEs and Pool Non-Paged Bytes.

 

The output csv can be used as a checkpoint for server health and can be used for reporting matrix. The script can easily be modified to add more performance counters and registry checks as necessary.

 

# Read file and store server names in variable

$Servers = (Get-Content .\servers.txt)

# Write header in output file

# Store header in variable
$headerLine =
@"

Server Name,Boot String,3GB,PAE,UserVA,Basevideo,SystemPages,Free System PTEs, Pool Non-Paged Bytes
"@

# Write header to file
$headerLine | Out-File .\results.csv -Encoding ASCII -Append

function getVitals()

{
	# Set server to connect to
	$Server = "$_"

# Read SystemPages from servers

	# Set Registry Key variables
	$REG_KEY = "System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"
	$VALUE = "SystemPages"

	# Open remote registry
	$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)

	# Open the targeted remote registry key/subkey
	$regKey= $reg.OpenSubKey($REG_KEY)

	# Read and Store SystemPages value in variable
	$SystemPages = $regkey.getvalue($VALUE)

	# Close the Reg Key
	$regKey.Close()

# Read Boot.ini from Servers

	# Store Boot.ini contents in variable
	$iniContent = Get-Content "\\$Server\c$\boot.ini"

	# Store Boot string and values in variables
	$bootString = $iniContent[4] -replace ","," "
	$userva = ($bootString -split " " | foreach {if ($_ -match "userva") {$_}} | foreach {$_ -replace "/userva=",""})

	if ($iniContent[4] -match "3gb") {$3gb="Present"} else {$3gb="Missing"}
	if ($iniContent[4] -match "PAE") {$pae="Present"} else {$pae="Missing"}
	if ($iniContent[4] -match "basevideo") {$basevideo="Present"} else {$userva="Missing"}

# Read System Pages and NPP values from Performance Counters

	# Read performance counters
	$freeSPTEs = (Get-WmiObject Win32_PerfFormattedData_PerfOS_Memory -ComputerName $Server).FreeSystemPageTableEntries
	$poolNPBytes = (Get-WmiObject Win32_PerfFormattedData_PerfOS_Memory -ComputerName $Server).PoolNonPagedBytes

# Write data to file

	# Store result string in a variable
	$result = "$Server,$bootString,$3gb,$pae,$userva,$basevideo,$SystemPages,$freeSPTEs,$poolNPBytes"

	# Write results to file
	$result | Out-File .\results.csv -Encoding ASCII -Append

}


# Get vitals for each server stored in $Servers array
$Servers | %{getVitals}
Print Friendly, PDF & Email