PowerShell: long lines in Get-History

If I just save my history thus…

get-history | clip

, then I find beyond 80 characters whatever, you get truncation (note the ellipses):


Outputting to json helps…

Get-History | ConvertTo-Json

, but it is still a bit of a hunt to find what you want:


First, we will get the history into an array of strings, splitting on Newline:


$history = Get-History | ConvertTo-Json
$historyLines = $history -split [System.Environment]::Newline

From the previous screenshot, I am only interested in those lines which contain [CommandLine]:

$historyLines | % {if ($_ -match "CommandLine") { $_ }}


But I want to exclude the repeated “CommandLine” etc. For now, I’ll just cheat. I found that the start of the variable part is at offset 25, so I’ll just do this for now:

$historyLines | % {if ($_ -match "CommandLine") {$_.substring(25, $_.length - (25+2)) }}

, which gives this, which is good enough for now:


Finally, bringing the 3 lines together:

$history = Get-History | ConvertTo-Json
$historyLines = $history -split [System.Environment]::Newline
$historyLines | % {if ($_ -match "CommandLine") {$_.substring(25, $_.length - (25+2)) }}


Aliases, plus other ways to get the full history

h | Format-List -Property *
h | Format-List -Property CommandLine
h -id 31 -Count 10
h -id 31 -Count 10 | fl
h | fl -Property CommandLine | clip


PowerShell: clipboard / spreadsheets

Normally you would do most of this stuff with a formula or macro in a spreadsheet. For the purposes of this, let’s assume you don’t have that ability:

(I’m using small numbers, but of course the principle can be extended to much larger sets.)

PowerShell: string/number formatting

In PowerShell, you can do a lot of your string formatting needs using standard numeric formatting in ToString. This MSDN post gives chapter and verse.

And for the PowerShell, the screenshots are enough to cover it:

Agile Atlas related

Agile Atlas
Scrum Principles

from this location


The idea is to make good use of dead time, mostly commuting, by converting large chunks of text into wav or mp3 files, to play on a iPod type thing. The specific prompt for this is the Agile Atlas – it seems that if you know that by heart, and its cousin ?, then you have the ScrumMaster exam cracked, ha ha.

Getting there right now is a mixture of manual and scripted steps.

  1. Input: large text file (in time this will or could be a PDF).
  2. Output: An mp3 file
  3. Steps:
    1. Save the file as a .txt to the file system – it can have empty lines
      1. If the input text is html, with ads etc spread throughout, then Evernote Clearly is a useful tool for cleaning that up
    2. Use the PowerShell script below to speak the text to a .wav file
    3. Right now, use iTunes to convert the .wav to a .mp3 format
  4. Improvements needed:
    1. Accept PDF format
    2. Write directly to MP3 if required, not WAV. However there are licencing considerations around the Lame mp3 encoder, which seems to be the one that the bulk of people use.

The input text:

Values from the Agile Manifesto

Scrum is the best-known of the Agile frameworks. It is the source of much of the thinking … (snip)

(snip) … and to ensure that they produce the best possible Product Increment. They perform Product Backlog Refinement to prepare for the next Sprint’s planning meeting. They end the Sprint with the Sprint Review and Sprint Retrospective, reviewing the product and their process.

— Scrum Alliance Core Scrum

I must say, WordPress.com is looking pretty handy – so if you want to embed code in your post, it knows about a lot of languages.

Let’s give it a try with the PowerShell that turns the above into a .wav file:

<# .Synopsis Convert the text input to the named wav file .Example Write-Output "Curses be, now this is all I have " | Convert-TextToWav -WavFile "D:\scratch\x3.wav" .Example Get-Content D:\scratch\testdata\data.txt | Convert-TextToWav -WavFile "D:\scratch\x5c.wav" .Example 2 step: trim blank lines (as they otherwise cause a null object exception), write to a scratch file Get-Content D:\books\AgileAtlas.txt | % {$_.TrimEnd()} | Where {$_ -NE ""} > .\temp.txt
    Get-Content .\temp.txt | Convert-TextToWav -WavFile "D:\scratch\x5d.wav"
    Get-Content D:\books\AgileAtlas.txt | % {$_.TrimEnd()} | Where {$_ -NE ""} | Convert-TextToWav -WavFile "D:\scratch\Out.wav"
function Convert-TextToWav {
        [parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
        [parameter(Mandatory=$true, Position=1)]

    begin {
       if ($inputObject) {
          Write-Output $inputObject | &($MyInvocation.InvocationName) $wavFile -wait:$wait -purge:$purge -passthru:$passthru
       } else {
          [Reflection.Assembly]::LoadWithPartialName("System.Speech") | out-null
          $speaker = New-Object System.Speech.Synthesis.SpeechSynthesizer
          $speaker.SetOutputToWaveFile( $(if( Split-Path $wavFile ) { $wavFile } else { "$pwd\$wavFile" }) )

    process {
        if ($_) {
            $speaker.Speak(($_ | Out-String))

    end {

And how that looks as a picture: