Migrate from Spaceguard to FSRM

For years a company called Tools4Ever have been producing the excellent Spaceguard, providing flexible quota management for network shares. With the release of Windows Server 2008 R2 Microsoft introduced FSRM (File Server Resource Monitor), providing almost identical functionality out the box.

One of the time consuming aspects of switching to the Microsoft solution can be transferring existing quotas from Spaceguard to FSRM. Thankfully Spaceguard have an option to export the configuration, which we can parse with Powershell and create the shares.
Continue reading Migrate from Spaceguard to FSRM

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.

$compList = "LONDON,BRISBANE"
$date = [System.Management.ManagementDateTimeConverter]::ToDMTFDateTime((Get-Date "01/11/2012"))
foreach ($computerName in $compList)
{
	$compCrashes = 0
	try
	{
		$compCrashes = Get-WmiObject -Computername $computerName -Class Win32_ReliabilityRecords -Filter "SourceName='EventLog' AND EventIdentifier='6008' AND Timegenerated >= '$date'" | group __CLASS | select Count
	}
	catch{}
	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"
    try
    {
      $objDisk = Get-WmiObject -Computername $computerName -Class Win32_Volume -Filter "DriveLetter='$($disk.DeviceID)'"
      $objDefrag = $objDisk.DefragAnalysis()
      $objDefragAnalysis = $objDefrag.DefragAnalysis;
      $diskFragmentation = $objDefragAnalysis.TotalPercentFragmentation
    }
    catch{}
    $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