Monday, January 19, 2009

Some notes on cmd line editing for Powershell in v2 CTP 3. It is often nice to be able to use a command line editor like Vim or Edlin when writing simple scripts. This allows the administrator to stay in one shell and one environment. Edlin allows the user to see the command history above and the editing space below. Bruce Payette's work lead me to create this function that replaces the venerable 'copy con' in DOS: 
function copy_con {[console]::In.ReadToEnd()}

My 'copy_con' function can be used to write to file or  variable:
copy_con > a.txt 
or
$a = copy_con

The same functionality is achieved in v2 CTP3 with read-host.

The 'out-gridview' cmdlet in CTP3 allows you to combine multiple output in one grid; a more readable and searchable window for multiple help files:  $a | %{help $_ -detailed} | out-gridview

Using the 'history' to create simple scripts is easy: 
$test_out = 25..30 | history| %{$_.CommandLine}

To execute the collection of commands from a variable:
$test_out  | %{Invoke-expression $_}


No comments: