How to

Monitoring Storage Pool Health – GriffinMonitor Module

There have been times in the past (more than I like to remember) where I’ve had a hard drive fail, a raid 5 fail, and eventually I am sure I’ll have a Storage Pool fail at some point with my lab environment. The best way to avoid this is by introducing active and heavy monitoring. In my work world I am very good and forward thinking when it comes to this; however no matter how many times it happens in my home environment I still fail at maintaining the system.

When Server 2012 was released with the introduction of Storage Pools I had just lost my RAID 5, I decided it was the right time to implement Storage Pools as my primary storage at home. It uses parity which is basically a software raid, and I was able to use cheap consumer drives along with USB drives (YAY! more space since I was out of it inside of the server.)

I’ve been running Storage Pools for over a year, knowing one major issue with my setup. I have absolutely no monitoring in place, and if I were to have a drive fail it could be weeks… maybe months before I realize an issue exists. I recently went through updating my home lab from Server 2012 to 2012 R2 and decided I needed to stop fooling around with my data and get some monitoring in place.

Well the first issue came along… how am I going to monitor my Storage Pool? Sadly there is no easy alerting of an unhealthy Storage Pool built in… I’m sure there are third party tools, but do I really want to go through the hassle of setting that up for just my Storage Pool? The good news is that PowerShell has some fantastic cmdlet’s available for working with storage.

When I started building my monitoring solution I initially thought… a simple script on a scheduled task will get the job done. As I built it out, I decided that I needed to go further than I have in the past, I needed to build a cmdlet, then once I finished that I thought why stop there? Why not built my first module? This module currently only contains a single PowerShell cmdlet, but as time goes on I hope to build out many more that I can continue to use in my environment at home. Below is the entire source of the psm1 file that is stored in my Modules directory along with installation instructions and directions on how to use the cmdlet.

Using Alert-GMUnhealthyStoragePool:

This is a fairly straightforward cmdlet, only 3 mandatory parameters and it works. There are quite a few restrictions surrounding the SMTP Server including it cannot use TLS or SSL (Currently) and it doesn’t accept Authentication. These will be added in the future but for the first iteration of it I was going for quick and dirty for a lab environment.

Example:

Alert-GMUnhealthyStoragePool -SMTPServer smtp.example.com -ToAddress Joe@example.com -FromAddress alert@example.com

 The Module Code:

#Requires -Version 3 
#Requires -Module Storage
<#
 # Module Name: GriffinMonitor.psm1
 # Version: 1.0
 # Created: 05/22/2014
 # Author: Matt Griffin (MattBlogsIT.com)
 # Purpose: This Module is a set of custom cmdlet's that are used to alert of potential health concerns in your Windows Environment
 # Legal: This module was built by Matt Griffin for use in his home lab environment. This module comes with no warranty or guarantee. 
 #        This module is provided to be used at your own risk and will not have any support backing it up.
 # History: Matt Griffin 05/22/2014
 #          Initial creation of Module with first cmdlet Alert-GMUnhealthyStoragePool
 #>
function Alert-GMUnhealthyStoragePool
{
    <#
    .Synopsis
       This function will check all of your local systems storage pools and send you can alert when one of them enters a state other than healthy.
    .DESCRIPTION
       This function will check all of your local systems storage pools and send you can alert when one of them enters a state other than healthy. The alert will be sent through email.
    .PARAMETER SMTPServer
       This parameter will be used to specify a standard SMTP Server that doesn't require SSL or TLS.
    .PARAMETER ToAddress
       This parameter will be used to specify the email address to which the alert messages will be sent.
    .PARAMETER FromAddress
       This parameter will be used to specify the email address from which the alert messages will be sent.
    .EXAMPLE
       Alert-GMUnhealthyStoragePool -SMTPServer smtp.example.com -ToAddress Joe@example.com -FromAddress alert@example.com
    #>
    [CmdletBinding()]
    [OutputType([int])]
    Param(
        # SMTPServer This parameter specifies the SMTP Server to utilize when alerting of unhealthy Storage Pool
        [Parameter(Mandatory=$true,Position=0)]
        $SMTPServer,
        
        # ToAddress This is the email address that the alert message will be sent to
        [Parameter(Mandatory=$true,Position=1)]
        $ToAddress,

        # FromAddress This is the email address that the alert message will be sent to
        [Parameter(Mandatory=$true,Position=2)]
        $FromAddress
    )
    #Import Required PowerShell Module
    Import-Module -Name Storage

    $storagePools = Get-StoragePool

    foreach($pool in $storagePools){
        if($pool.HealthStatus -ne "Healthy" -and $pool.IsPrimordial -ne "True"){

            $physicalDisks = $pool | Get-PhysicalDisk | 
            Select FriendlyName, Manufacturer, Model, SerialNumber, OperationalStatus, HealthStatus, Usage, Size | ConvertTo-Html

            #Create hash table to splat for Send-MailMessage
            $mailMessageParams = @{'SmtpServer'=$SMTPServer;
                                   'From'=$FromAddress;
                                   'To'=$ToAddress;
                                   'Subject'="The Storage Pool $($pool.FriendlyName) is currently $($pool.HealthStatus) on $env:computername";
                                   'Body'=($physicalDisks | Out-String);
                                   'BodyAsHtml'=$true}

            Send-MailMessage @mailMessageParams
        }
    }
}

Installation Instructions:

  1. Navigate to C:\Users\<username>\Documents\WindowsPowerShell\Modules\GriffinMonitor
    1. (Note: If the directory doesn’t exists you must create it.)
  2. Save the above code in a file named GriffinMonitor.psm1 under the above directory
  3. Create a Scheduled Job using PowerShell
    1. #The below PowerShell commands will schedule the cmdlet to run every 30 minutes using the SMTPServer xxx.xxx.xxx.xxx, emailing to joe@example.com and coming from noreply@example.com - Make sure you update the parameter values.
      $trig = New-JobTrigger -Once -At "5/22/2014 0am" -RepetitionInterval (New-TimeSpan -Minute 30) -RepetitionDuration ([TimeSpan]::MaxValue)
      Register-ScheduledJob -Name CheckStoragePoolHealth -ScriptBlock { Alert-GMUnhealthyStoragePool -SMTPServer xxx.xxx.xxx.xxx -ToAddress joe@example.com -FromAddress noreply@example.com} -Trigger $trig

Once it is scheduled, keep an active eye on your inbox for when your Storage Pool goes unhealthy!

Miscellaneous Notes:

  • This module was built and tested using PowerShell v4 on Server 2012 R2 running a single Storage Pool.
  • This module “should” work with Server 2012 running PowerShell v3 with one or many Storage Pools
  • This module comes with no guarantee or support, this is a run at your own risk and I take no responsibility for any repercussions that may occur by running this.
    • With that being said I’ll try my best to assist anyone who may have questions if you post in the comments of this thread.

Monitoring Storage Pool Health – GriffinMonitor Module Read More »

Configure Surface to use MicroSD as Primary Storage

After about a week of excitement and playing around with features, I decided it was time to start optimizing and making this thing run the way I wanted. The first thing I noticed was that I could not use my SD card with my Libraries, so all my apps are going to by default save to the local SSD, which is far from what I want. I knew there had to be a way around this, so I started digging in. I feel I finally have it to the point where others should be doing the same thing, and once done, you can forget about it.

  • Create a VHDX and save it on the SD card
  • Create directories on this VHD for your specific libraries
    • Documents
    • Music
    • Video
    • Pictures
  • Configure the libraries
  • Enable Indexing on the VHDX – This is important because the Photos app doesn’t work right without it.
  • Have a script automatically Attach the VHD on Boot

If you would like to know the exact steps to take, please continue reading.

Creating a VHD

  1. Open Charms Menu (Swipe in from the right side of the screen)
  2. Click Settings
  3. Click Tiles
  4. Change “Show administrative tools” to Yes
  5. Swipe from the bottom of the screen
  6. Click All apps
  7. Under “Administrative Tools” click Computer Management
  8. Click “Disk Management”
  9. Click “Action”
  10. Click “Create VHD”
  11. Browse to the SD Card’s storage and name the VHD whatever you want
  12. Allocate as much of the SD’s storage you want to this VHD,
  13. You can decide between Fixed or Dynamically expanding. I went with Dynamically expanding.
  14. Find the newly created disk in the lower panel, which should be “Disk 2”
  15. Right-click where it says “Disk 2”
  16. Click “Initialize Disk”
  17. Click OK
  18. Right-click “Unallocated”
  19. Click “New Simple Volume…”
  20. Click “Next >”
  21. Click “Next >”
  22. Select the Drive letter you want (can be anything)
  23. Click “Next >”
  24. Name the Volume whatever you want
  25. Click “Next >”
  26. Click “Finish”

Create/Configure Library Directories on VHD

  1. Click the “Libraries” icon from the “Task Bar”
  2. Single click “Documents”
  3. Click “Manage under “Library Tools” from the ribbon
  4. Click “Manage library”
  5. Click “Add”
  6. Browse to the newly Attached VHD you just created
  7. Click “New Folder”
  8. Name it whatever you want (Eg: Documents)
  9. DO NOT OPEN THE FOLDER, select the folder and click “Include folder”
  10. Remove the Default Personal folder
  11. Click OK
  12. Click “Set save location”
  13. Select the newly created folder
  14. Repeat steps 1-13 for the following
    1. Music
    2. Pictures
    3. Videos

Enable Indexing on VHD – Very Important

  1. Open the “Charms Menu”
  2. Click “Search”
  3. Type “Indexing Options”
  4. Click Settings
  5. Open “Indexing Options”
  6. Click “Modify”
  7. Select the newly Attached VHD
  8. Click OK
  9. Click Close

Create Script to Auto Attach on Startup

  1. Open PowerShell as an Administrator
  2. Type “Set-ExecutionPolicy RemoteSigned”
  3. Press Enter
  4. Type “y”
  5. Press Enter
  6. Click Computer from the navigation bar on the left of the Libraries folder
  7. Open the C: Drive
  8. Create a new folder named “PoSH”
  9. Double click the new folder
  10. Right-click in the white area and navigate to “New > Text Document”
  11. Name it Auto-Mount.ps1
  12. Open the new file with Notepad
  13. Paste the below code in, don’t forget to modify the red text to the path you saved the VHDX file at
    1. “Mount-DiskImage D:\YourVHD.vhdx”
  14. Open the “Charms Menu”
  15. Click “Search”
  16. Type “Task Scheduler” and open it
  17. Click “Task Scheduler Library”
  18. Click “Action”
  19. Click “Create Task…”
  20. General Tab
    1. Name: Attach SD VHD
    2. Location: \
    3. Description: This is the Task that automatically attaches the VHD file on the SD card on system boot.
    4. “Click Change User or Group…” type in SYSTEM
    5. Check “Run with highest privileges”
  21. Triggers Tab
    1. Click “New…”
    2. Begin the task: At startup
    3. Click OK
  22. Action Tab
    1. Action: Start a program
    2. Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    3. Add arguments: C:\PoSH\Auto-Mount.ps1
    4. Click “OK”
  23. Conditions Tab
    1. Under Power uncheck “Start the task only if the computer is on AC power
    2. Click “OK”
  24. Have fun testing. I recommend opening the Camera app and taking some pictures, making sure it index the new ones, try adding music to the folder make sure it shows up in the music app, the same thing for the Video app.

Update 12-30-2012: Thank you, Don, for reminding me you need to set the execution policy on the machine first.

Configure Surface to use MicroSD as Primary Storage Read More »

Setting up a HomeGroup with Windows 8

While recently blogging about using my Surface to share media from my desktop to my Xbox it occurred to me. Some people may not know how to setup a HomeGroup, and it would be very useful to have step by step instructions to ease the adoption of sharing Music and Videos across all of you’re Windows 8 computers in your home.

This is very simple, just follow the steps below.

  1. Open your Charms Menu (bottom right corner using mouse | Swipe in from right side of screen using touch)
  2. Click Settings
  3. Click Change PC Settings
  4. On the left side of this screen scroll to bottom and click HomeGroup
  5. Under Libraries and devices select what you would like to share
  6. Under Membership if you do not already have a HomeGroup create one, if you have one go to the machine that host it and get the Password to join it and enter it there.

Once you have completed that you can access you’re shared content on any computer that is a member by simply opening the File Explorer and under Home Group you will see the users sharing content. You can also add additional files by modifying you’re libraries to include folders in other locations than the default.

Setting up a HomeGroup with Windows 8 Read More »