Quantcast
Channel: DIY IT Shop » powershell
Viewing all articles
Browse latest Browse all 9

Check Server Crash Settings via PowerShell

$
0
0

I ran into a situation this week where I needed to check the crash/memory dump settings on multiple servers at one time this week, so I wrote a PowerShell script to help me do so.

Create a new ps1 file called get-crashinfo.ps1 and copy paste the following code into it:

Function Get-CrashInfo {
	param (
		[string]$Server
	)

	begin {
		$myType = [Microsoft.Win32.RegistryHive]::LocalMachine;
		$myKeyPath = "SYSTEM\CurrentControlSet\Control\CrashControl";
		$myKeys = @("CrashDumpEnabled","AutoReboot","LogEvent","DumpFile","MinidumpDir","Overwrite","SendAlert");
	}
	process {
		foreach ($thisServer in $Server) {
			if ($thisServer) {
				$thisServer = $thisServer.ToUpper()
				try {
					$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($myType, $thisServer)
					$regKey = $regKey.OpenSubKey($myKeyPath)
					$OutputObj  = New-Object -Type PSObject
					$OutputObj | Add-Member -MemberType NoteProperty -Name ServerName -Value $thisServer.ToUpper()
					foreach ($thisKey in $myKeys) {
						$OutputObj | Add-Member -MemberType NoteProperty -Name $thisKey -Value $regKey.GetValue("$thisKey","0").ToString()
					}
					$OutputObj
				}
				catch {
					Throw Write-Host -foregroundcolor red "Could not connect to $thisServer"
				}
			}
			else {
				Throw Write-Host -foregroundcolor red "You must specify a server."
			}
		}
	}
	end { }
}

Once saved, open up powershell using an account that has Administrator rights on the server you are connecting to and then import the function by running:

. <path>\get-crashinfo.ps1

Once the ps1 file is imported, run the command by typing:

get-crashinfo -server <ServerName>

You will receive output that looks like the following:

ServerName       : <ServerName>
CrashDumpEnabled : 2
AutoReboot       : 1
LogEvent         : 1
DumpFile         : C:\WINDOWS\MEMORY.DMP
MinidumpDir      : C:\WINDOWS\Minidump
Overwrite        : 1
SendAlert        : 0

The output is fully pipeable to other cmdlets and formatting functions like ft and select.

Should you need more information about the meaning of the output from this command, please visit http://blogs.technet.com/b/askperf/archive/2008/01/08/understanding-crash-dump-files.aspx.


Viewing all articles
Browse latest Browse all 9

Trending Articles