Archives for the Month of August, 2010

PowerShell Cookbook – O’Reilly EBook Deal of the Day

For today only, O’Reilly is offering the electronic version of the Windows PowerShell Cookbook for only $9.99. This gives you unrestricted access to DRM-free PDF, MOBI (Kindle, etc) and ePub versions of the book.

If you have an iDevice, the Stanza book reader (among several others) supports both the PDF and ePub file formats.

Get it while it’s hot!

Use code DDWPC http://oreil.ly/cFRco0

PowerShell Cookbook V2 Now Available

On Friday, we wrapped up the final details of the PowerShell Cookbook, V2. O’Reilly has already made the electronic edition available, which is a great resource for searching, copying, pasting, and working with the content in its native form. If you or your company subscribes to Safari, it should be available shortly.

If you’re a fan of the printed version, it's off to the printers now, and has a scheduled "in-stock" date of 8/24: the date when it'll be in boxes in the shipping / receiving area of book stores. It takes about a week for books to migrate onto shelves, so the official "when can I get it" date is 8/31.

It's almost 900 pages now, despite my best efforts to keep it svelte 🙂 I dropped the chapters on Exchange and MOM (since there are dedicated books and support materials for those now), and dropped a few appendixes that are now covered much more effectively in the in-box help. Since much of the V1 book is about filling "missing pieces" from V1, and we filled tons of "missing pieces" from V1, much of the new content directly replaced recipes that existed in the V1 book.

Dropping the chapters on Exchange and MOM was also done in response to feedback. While they provided cursory coverage of the technologies, they were intended primarily to introduce Admins to the wider PowerShell ecosystem. Now that there are entire books written to cover PowerShell-based products (i.e.: VMWare, Exchange, MOM, etc), the Cookbook can now focus on the core technology. Aside from the Exchange / MOM updates, the "Description" sections of many recipes have been beefed up in response to feedback. Most go into significantly more detail, or discuss more of the underpinnings of the recipe or what it covers.

And then, of course, there's the "new stuff". The book now has about 430 recipes, almost double what the first version had. It's sometimes easy to forget how transformative PowerShell V2 is, but it consisted of over two thousand source code checkins!

All-told, the second edition took about 560 hours. That's a lot, but what surprised me is that it ended up being only about an hour per print-ready page: including research, drafts, reviews, copy editing, and everything else wrapped in the project.

If you liked the first version of the PowerShell Cookbook, you’ll like this version even more 🙂

Aurora Monitoring with PowerShell

Over the past few days, Astronomy resources have been making a big splash about a couple of coronal mass ejections (CME) primed to cause widespread visibility of the Aurora Borealis. Last night was when the first one hit, and its effects extended deeply into southern Canada and parts of the northern US.

There may be another round tonight, so maybe this post can help you catch your first Aurora 🙂

NOAA has a couple of good resources, and one I was keeping special track of shows where the effects are the greatest:

aurora_2010-08-04-14-49

Areas that are red are seeing the greatest magnetic activity.

After refreshing this page a bunch last night and watching as the red started getting closer and closer to Washington state. It was getting late and I still couldn’t see it, so I decided instead to write a script to alert me when it peaked.

This script measures the amount of red over (and above) Washington State, and keeps monitoring until it senses a decrease. Once it senses a 5% decline, it alerts me. Crude image recognition at its finest!

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
## Launch the interesting sites
Start-Process "http://www.swpc.noaa.gov/pmap/pmapN.html"
Start-Process "http://www.swpc.noaa.gov/rt_plots/pro_3d.html"

Add-Type -Assembly System.Drawing
$wc = New-Object System.Net.WebClient

## The monitor region. Get these coordinates from the X,Y positions
## your mouse shows when hovering around any saved file (pmapN.gif) in mspaint.
$startX = 130
$startY = 300
$endX = 144
$endY = 339

## Get the "Aurora Index" for the given region
function Get-AuroraIndex
{
    ## Download the file
    $url = "http://www.swpc.noaa.gov/pmap/gif/pmapN.gif"
    $null = New-Item -Type Directory
 
c:\temp\aurora -Force
    $destination = "c:\temp\aurora\aurora_" + ((Get-Date).ToString("yyyy-MM-dd-HH-mm")) + ".gif"

    try
    {
        $wc.DownloadFile($url, $destination)
    }
    catch { return }

   
    $image = [System.Drawing.Bitmap]::FromFile($destination)

    $totalRed = 0
    for($x = $startX; $x -lt $endX; $x++)
    {
        for($y = $startY; $y -lt $endY; $y++)
        {
            $totalRed += $image.GetPixel($x, $y).R
        }
    }

    $totalRed
}

$lastValue = $null

while($true)
{
    $currentValue = Get-AuroraIndex
    if($currentValue)
    {
        ## Catch the rising aurora
        if($currentValue -gt ($lastValue * 1.05))
        {
            $lastValue = $currentValue
            "Aurora is rising @ " + (Get-Date) + ". Current value: $currentValue"
        }

        ## Catch a falling aurora
        elseif($currentValue -lt ($lastValue * 0.95))
        {
            "Aurora is falling @ " + (Get-Date) + ". Current value: $currentValue"
            while($true)
            {
                C:\windows\Media\notify.wav
                Start-Sleep 5
            }
        }
       
        ## Aurora is stable
        else
        {
            "Aurora is stable @ " + (Get-Date) + ". Current value: $currentValue"
        }
    }

    Start-Sleep 30
}