How To – Check crashed servers using PowerShell

Following on from my previous post about how to check disk space and volume fragmentation of servers, it may be useful to also determine if a system has crashed in a given timeframe. From Windows 2008 R2 onwards a new WMI class was introduced, Win32_ReliabilityRecords. This class contains EventLog information relating to Windows Reliability.

The PowerShell script below will connect to each server in a list ($compList) and check for reboots.

$date = [System.Management.ManagementDateTimeConverter]::ToDMTFDateTime((Get-Date "01/11/2012"))
foreach ($computerName in $compList)
	$compCrashes = 0
		$compCrashes = Get-WmiObject -Computername $computerName -Class Win32_ReliabilityRecords -Filter "SourceName='EventLog' AND EventIdentifier='6008' AND Timegenerated >= '$date'" | group __CLASS | select Count
	Write-Host $ComputerName $compCrashes.Count

This could be expanded to store the results in a table and send the results using Send-MailMessage, but I’ll leave that to the reader.
Continue reading How To – Check crashed servers using PowerShell

How-To – Check diskspace using PowerShell

Sometimes it’s useful to quickly get an idea of certain usage statistics from a number of servers. Without monitoring and capacity management systems in place it may be difficult to capture information such as disk usage, fragmentation etc.

Rather than logging into each server and manually gather the information, why not automate the task using WMI and PowerShell? The script below will connect to each server in the list ($compList) and determine the free disk space and volume fragmentation.

$compList = "LONDON", "BRISBANE"
$DiskResults = @()
foreach ($computerName in $compList)
  Write-Host $computerName
  $objDisks = Get-WmiObject -Computername $computerName -Class win32_logicaldisk | Where-Object { $_.DriveType -eq 3 }
  ForEach( $disk in $objDisks )
    $diskFragmentation = "Unknown"
      $objDisk = Get-WmiObject -Computername $computerName -Class Win32_Volume -Filter "DriveLetter='$($disk.DeviceID)'"
      $objDefrag = $objDisk.DefragAnalysis()
      $objDefragAnalysis = $objDefrag.DefragAnalysis;
      $diskFragmentation = $objDefragAnalysis.TotalPercentFragmentation
    $ThisVolume = "" | select ServerName,Volume,Capacity,FreeSpace,Fragmentation
    $ThisVolume.ServerName = $computerName
    $ThisVolume.Volume = $disk.DeviceID
    $ThisVolume.Capacity = $([Math]::Round($disk.Size/1073741824,2))
    $ThisVolume.FreeSpace = $([Math]::Round($disk.FreeSpace/1073741824,2))
    $ThisVolume.Fragmentation = $diskFragmentation
    $DiskResults += $ThisVolume
$DiskResults | ft

This could easily be extended to capture windows reliability information using Win32_ReliabilityRecords to determine if servers have crashed recently or other information. Check back for a future post about that.
Continue reading How-To – Check diskspace using PowerShell

Cisco Device Info 1.3.0 Released

Cisco Device Info (CDI) is a Windows application to retrieve runtime information from Cisco equipment such as routers and switches. This is achieved using the SNMP protocol. Late last week I released version 1.3.0, some important enhancements are as follows:

  1. Enhanced the way additional columns can be shown (Right-Click table headers). Any column can now be removed from display and Interface index and descriptions can be made visible (not shown by default);
  2. When hovering over a line on the interface usage chart a tool-tip appears showing the interface name. This is useful for devices with dozens of interfaces;
  3. Where no data for one tab is available for that device, the tab will be hidden. For example the “Switch Stack” tab will not be shown for ISR routers;
  4. Fixed bug were user interface could be left in an inconsistent state following a router failing to respond;
  5. Fixed bug where interfaces with speeds greater than 4GB/s were misreported;
  6. Improved error handling experience of the interface usage chart following SNMP timeouts due to slow responding, or no longer available devices;

For more information, or to download Cisco Device Info (free to use in a home lab) head over to the download page for Cisco Device Info.
Continue reading Cisco Device Info 1.3.0 Released