Words about things. Introverted, Geeky, DevOps.

Sunday Ride with EP

I had a lovely ride with my friend Elaine today, though we got a bit lost.
Seems like Strava crashed at some point, as Elaine tracked us as having gone 45 miles, not ~42.

Bottles of Beer

function Write-BottlesOfBeer {  
        [int]$bottles = 99
    $b='bottles of beer'
    $w='on the wall'
    $n='no more'

    $bottles..1 | %{  
        "$_ $b $w, $_ $b.`r".Replace('bottles',"bottle$(if($_ -gt 1){'s'})")
        "Take one down and pass it around, $(if(($_-1) -ge 1){$_-1} else {$n}) $b $w.`r".Replace('bottles',"bottle$(if($_ -ne 2){'s'})")
        if ($_ -eq 1) {
            "No more $b $w, $n $b. `r"
            "Go to the store and buy some more, 99 $b $w."

I thought I'd have a go at a PowerShell version of 99 Bottles of Beer, to make something slightly nicer for 99-bottles-of-beer.net.

Slightly lazy code-golf-esque approach, but I think it's a little nicer than the version currently up for PowerShell.

I also wrote Pester testing for it, for the heck of it, as I've been feeling bad about how badly I wrote some tests for a recent technical evaluation. Sigh.

. ($PSCommandPath -replace '\.tests\.ps1$', '.ps1')

$lyrics = (Invoke-WebRequest 'http://www.99-bottles-of-beer.net/lyrics.html').ParsedHtml.getElementById('main').OuterText.Split("`n") | Select-Object -Skip 1

Describe 'Write-BottlesOfBeer' {  
  Context 'Running without arguments'   {
    It 'runs without errors' {
      { Write-BottlesOfBeer } | Should Not Throw
    It 'gets it right' {
        $i = 0
        Write-BottlesOfBeer | %{
            $_ | Should Be $lyrics[$i]

Passing Tests after the last silly non-compliance

Amazon Echo - CuSteam Skill

After a few days tussling with the out of date walkthroughs Amazon provide for developing Alexa Skills, I was happy to get this working:

...now I've just got to get something useful to other people working.


After seeing this amazing thread, I had a quick think about the problem mentioned here.

I wanted [to export] PowerShell Hashtables [to] the file [...] instead of JSON.
The reason this came up was that I was pulling configuration hashtables out of scripts and plac[ing] them into files. This worked when I was editing them by hand and just importing them in my scripts, but then I wanted to generate these config files or make updates to them and could not do it in any intuitive way.

This user wanted to use Hashtable formatting when exporting to files, instead of standard JSON (which has a pre-installed cmdlet). Like this:

    HostName    = "Server"
    OS          = "Windows Server 2012 R2 Standard (x64)"
    Environment = "VMWorkstation"
    Role        = "BaseSystem"

Instead of this:

    "Environment" : "VMWorkstation",
    "HostName"    : "Server",
    "OS"          : "Windows Server 2012 R2 Standard (x64)",
    "Role"        : "BaseSystem"

I had a quick attempt at a function to do this. Turns out that you can do it very quickly, but it gets more interesting if you want to format it nicely.

function Export-HashTable {  
        [Parameter(Mandatory, ValueFromPipeline)]
    process {
        $divWidth = ($HashTable.Keys.Length | Measure-Object -Maximum).Maximum + 8

        $hashString = ("$(if($Name){"`$$Name = "})@" + ($HashTable | ConvertTo-JSON) -replace '":','"=' -replace '",
').Split("`n") | %{if($_ -match '^(\W+"\w+")=') {  
            $_ -replace '^(\W+"\w+")=',"$($Matches[1] + (' '*($divWidth - $Matches[0].Length)))="}
            else {$_}
    end {
        if ($Path) {
            Out-File -FilePath $path -InputObject $hashString -Encoding utf8
        else {
            return $hashString

An up to date copy can be found here.

Vulfpeck Live!

Holy heck, these guys are simply amazing. Here's their bandcamp. Their albums are great, but their live performances are just... something else.

I saw them live on Saturday 17th, at the Brooklyn Bowl at the Millenium Dome (O2 something?), and it was absolutely wonderful.

I've been enjoying the live shows posted on YouTube (though a few have now been taken down, sad face). As an aside: I totally understand if someone wants to take down a video of something because they're selling it - but it turns out I can't buy the stream anymore, because they only sold it prior to the event. Hmph.

Anyway, these guys rock, and I could go on for hours about how much I think so.

SysInternals Updater

I was just running a delightful batch script written by Jason Faulkner to update my SysInternals tools directory.

Sysinternals Updater

It was taking forever! At least 2 seconds per tool (regardless of state), and a huge chunk of time to download the current tool list. It seems to download everything, regardless of whether or not it's up-to-date.

I thought it may be far quicker in PowerShell with some more up to date methods, so I sketched this out. It's far less robust (won't attempt to kill processes if they're in use), as I actually don't want that functionality.

function Update-SysInternalsTools {  
    begin {
        $localTools  = Get-ChildItem $localDirectory -Filter *.exe
        $onlineTools = Get-ChildItem '\\live.sysinternals.com\tools' -Filter *.exe
    process {
        foreach ($tool in $localTools) {
            if ($tool.LastWriteTime -lt ($online = $onlineTools | ?{$_.Name -eq $tool.Name}).LastWriteTime) {
                Write-Verbose "[$($tool.Name)] requires updating..."
                try {
                    Invoke-WebRequest -Uri $online.FullName -OutFile $tool.FullName -ErrorAction Stop
                catch {
                    Write-Warning "$($tool.Name) failed to update."

if ($MyInvocation.InvocationName -NE '.') {Update-SysInternalsTools}  

I'll probably update the script shortly with kill-process-and-restart as an option (as well as a "download everything" argument, as it currently only updates tools that are present), but it seems to get through the listing far faster.

It's also currently just comparing LastWriteTime - it could actually grab the VersionInfo/FileVersion with Get-ItemProperty, but I thought that might add a very large chunk of (fairly unnecessary) delay. Will have to test it.

Google Chrome allows Tab-by-Tab muting

Was just going to re-enable NPAPI plugins in Chrome, and I found this:


Now that's cool! Slightly weirdly, I love exploring the about:flags page in Chrome (Canary, or otherwise) and finding things in various stages of development - and I always loved the functionality that allowed you to see which tab was playing audio.

On hover:
chromeflags-tabaudiomute-mouseover Context Menu:

Active Directory - Storing Bitlocker Recovery Info

A recent quick project was to enable storage of Bitlocker recovery data within Active Directory, instead of our moderately secure encrypted drive of text-files.

This is actually a really easy process (assuming you only have Windows 7 / 2008R2 and up on the domain), only needing to make a few adjustments to ACLs on ADComputer objects (allowing Computers to write to their own objects).

The Technet article describing this, along with the more convoluted method involved in sorting this out for anything below 2008R2 is here: Backing Up BitLocker and TPM Recovery Information to AD DS

Unfortunately, it's a bit of a hassle (very minor hassle, anyway) to load up ADSIEdit.msc, and navigate around to the correct object every time you want to retrieve a key... so I wrote a quick Powershell script to replace the VBScript linked in the above article.


function Get-BitlockerRecovery($Computers, $Credential) {
    $report = @()

    foreach ($Computer in $Computers) {
    $objects = Get-ADObject -Filter * -SearchBase (Get-ADComputer $Computer).DistinguishedName -Credential $Credential -Properties * | Where -Property ObjectClass -eq msFVE-RecoveryInformation

    foreach ($key in $objects) {
        $keyInfo = "" | Select Computer, RecoveryID, RecoveryPassword
        $keyInfo.Computer = $Computer
        $key.Name -match ".*\{(.*)\}" | Out-Null
        $keyInfo.RecoveryID = $matches[1]
        $keyInfo.RecoveryPassword = $key."msFVE-RecoveryPassword"

        $report += $keyInfo
    return $report

Get-BitlockerRecovery -Computers $Computers -Credential $Credential

I'm sure there's probably a nicer way to do it, and that this could be compressed down to three lines or so - but I think that's quite legible.

Sunday Bike-Ride (08/06/14)

Nice ride! Managed to miss my Dad at Gransden, Orwell, and Barrington, but otherwise lovely.
Also to note: The Royal Oak in Barrington stops serving drinks at 15:00. What the what!?

Streaming - Payday 2

Watch live video from Jinoxide on TwitchTV

I've been playing plenty of Payday 2 with the Playstuff gang recently - it's in vogue, after some great updates, publicity and trailers. Anyway, I thought I'd stream some of it.

I'd recommend watching the recent "Dentist" trailer, starring Giancarlo Esposito (recently Gus Fring, of Breaking Bad) plays an excellent shady dentist chap - and doing some of the best DLC / mid-term plan reveals I've seen in a pretty low-key released PR video.

Also the wonderful "Big Bank" trailer - which I really enjoyed. Both are embedded below.

Watch_Dogs - _Role Model


I've quite enjoying Watch_Dogs, playing it a little every few nights - it's not the new best thing since sliced bread, but it's quite interesting. I'm slightly disappointed by a lot of things in it - punishing damage in gunfights mixed with little to no downsides to anything relating to vehicles (beyond the driving model), boring and unvaried hacking minigames in a game that headlines "hacking", and a bit of a fluffed intro where you seem to get all the items from the start and then "get" them for the first time throughout the game.

One of the things I've been really bemused about is the annoyingly forced mission _Role Model, which I've just played today. Some spoilers follow, and I'll probably refer to it all fairly casually - as if you knew enough to be spoiled, really.

Objective: Kill 'em All

It'll surprise noone who knows me that I've been playing Watch_Dogs so far fairly quietly - only really killing when I really need to. I love the way that the vigilante/alignment meter seems to reel in the tendency among folk to drive around manically, running down countless faceless civilians.

There have been a few missions that require you kill enemies - mainly gang-members, or mob affiliated goons. Sure. There are a lot of weapons in the game, I do wonder if I should be playing it slightly more trigger-happily - but I've enjoyed the choices provided.

Until this mission.

Spoilers begin here.

The mission begins with Jackson (or "Jacks", the protagonist's nephew), going missing from his current hideaway. You, as the player, are then prompted to go and find him. You locate him (fine, done that before), travel to the location (yep), and are told to kill a moderately large amount of enemies.
No choices, no sneaking, no clever hack-around solution.

Slaughter them. Oh, and wipe out the reinforcements, when they inexplicably arrive (I managed to kill them all quietly, without any alerts or enemy shots fired).

That's all fine - I'm great at this!

You then go up to "rescue" Jacks to find that he's seen all of the bodies, is terrified of you, and is judging you - which I'd probably be fine with, if I'd had a choice.

I guess it's going to become obvious why, in future play (and will probably contribute wonderfully to Aiden's relationship with his sister), but it really grates after so many brilliant games that allow you the choice of killing or not. I suppose I was hoping for something similar here.