Debugger for Graphical PowerShell V2 CTP2

Graphical PowerShell V2 CTP2 still looks like a demo, basically speaking. Nevertheless, I find it already suitable for some tasks. Unfortunately it does not implement a few host features including default breakpoint debugger action. Breakpoints without action are simply ignored. Fortunately PowerShell provides a way to solve this. Here it is: simple and yet practically useful Add-Debugger.ps1. The archive also contains Test-Debugger.ps1 to play with and see how debugging goes (in any host, actually). Follow instructions in the script headers.

Download: (EDIT: the next version is here…)


Leave a comment

PowerShell.hrc for Colorer, version 1.3.4

PowerShell.hrc for Colorer, version 1.3.4


EDIT: This version is obsolete. The latest PowerShell.hrc is included into the featured version of PowerShellFar plug-in for Far Manager:


What’s new: REGEX and SQL schemes are supported in PowerShell literal strings.

Flexibility and power of COLORER is amazing – it not only supports tons of file formats, but also allows combining schemes together (e.g. HTML scheme supports embedded JScript, VBScript and etc. reusing their schemes). As for the PowerShell, in new version of PowerShell.hrc I tried to use REGEX and SQL schemes in literal strings.

  • REGEX scheme is used in string operand of -match, -notmatch, -replace and etc.
  • Here strings are processed with REGEX or SQL schemes starting with lines #REGEX or --SQL respectively. Note that regex normally should be created with option IgnorePatternWhitespace or it should use inline instruction (?x).

Examples of highlighting in PowerShell strings

### Regex in operands

"ab11* 'foo'" -notmatch '^ab[0-2](d+)*s+''(w+)\'''
'ab11* "foo"' -match "^ab[0-2]$(2 - 1)*s+$($null)$null`"foo\`""
'2007-9-23' -replace 'b(d{2,4})-([01]?d)-([012]?d)b', '$3/$2/$1'

### Regex in here strings

$re = @'
#REGEX Id and Name
#(?<Id>d+)           # #number
s+                    # spaces
(?<Name>[_a-zA-Z]w*)  # name

# how to use such a pattern:
New-Object Regex $re, 'IgnorePatternWhitespace'

### SQL in here strings

--SQL single quoted
FROM Table1
WHERE Data1 = '$literal'

--SQL double quoted
FROM $Table
WHERE $x = '$variable'

Leave a comment

Example of a PowerShell script converted to HTML with syntax highlighting

This is not a real script, it is a script used for testing of syntax description PowerShell.hrc for Colorer and covering related issues. Perhaps this HTML looks like a Christmas Tree, no problem, it is just a demo. One can configure Colorer according to his preferences. Take a look at how it handles and distinguishes expandable and not expandable string content and escaping rules, is not it a beauty?

Demo: highlighted PowerShell

EDIT: replaced large demo text with a link

1 Comment

Get-Drive.ps1 and Get-File.ps1 – Get all local files


The task of iterating through all local files may be not straightforward if there are several drives including removable, network or substituted drives and NTFS reparse points directories. Get-Drive.ps1 and Get-File.ps1 used together may help: Get-Drive.ps1 returns only local physical drives, Get-File.ps1 excludes reparse points.


# calculate total available free space in GB
(Get-Drive | Measure-Object AvailableFreeSpace -Sum).Sum/1GB

# get paths of all local .bak files
Get-File \ *.bak -Name


## Author   : Roman Kuzmin
## Synopsis : Get physical drives
## Returns System.IO.DriveInfo objects
## *) removable, network and subst drives are excluded.

$subst = [string](subst)
foreach($d in [System.IO.DriveInfo]::GetDrives()) {
    if ($d.DriveType -eq 'Fixed' -and $subst -notlike "*$($d.Name):*") {


## Author   : Roman Kuzmin
## Synopsis : Get all files
## Returns System.IO.FileInfo objects or full names.
## -Root: root directory(s); single \ or // denotes all physical drives.
## -Filter: simple file system filter.
## -Name: return full names as strings.
## *) requires Get-Drive.ps1.
## *) access errors are silently ignored.
## *) hidden and system files are included.
## *) reparse points directories are excluded.

    [string[]]$Root = '.',
    [string]$Filter = '*',

function DirectoryFiles([System.IO.DirectoryInfo]$di)
    # ignore errors
    trap {continue}

    # skip a reparse point
    if ($di.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {

    # files
    if ($Name) {
        foreach($f in $di.GetFiles($Filter)) {
    } else {

    # directories
    foreach($d in $di.GetDirectories()) {
        DirectoryFiles $d

if ($Root.Count -eq 1 -and ($Root[0] -eq '\' -or $Root[0] -eq '//')) {
    foreach($d in Get-Drive) {
        DirectoryFiles $d.RootDirectory
} else {
    foreach($d in $Root) {
        DirectoryFiles $d

Leave a comment

PowerShell syntax description for Colorer and Far Manager editor


PowerShell.hrc defines PowerShell syntax description for Colorer and Far Manager editor with FarColorer plugin.

EDIT: This version is obsolete. The latest PowerShell.hrc is included into the featured version of PowerShellFar plug-in for Far Manager:


<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE hrc PUBLIC "-//Cail Lomecb//DTD Colorer HRC take5//EN" "">
<hrc version="take5" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

Insert into catalog.xml a link to this:
<location link="<path>/PowerShell.hrc"/>

<prototype name="PowerShell" group="scripts" description="PowerShell">

<type name="PowerShell">

PowerShell.hrc version 1.3.1, 2007.03.21
PowerShell syntax description and .psfconsole features.
Created and tested for PowerShell 1.0 with Colorer-take5.beta5
Roman Kuzmin,

<import type="def"/>

<!-- Escaped -->
<scheme name="PSEscaped">
<regexp match="/`s+$/" region="def:Error"/>
<regexp match="/`./" region="def:StringContent"/>

<!-- Variable -->
<scheme name="PSVariable">
<regexp match="/$[w:]*w/" region="def:Var"/>
<block start="/${/" end="/}/" scheme="PSEscaped" region="def:Var" region00="def:PairStart" region10="def:PairEnd" region01="def:Var" region11="def:Var"/>

<!-- Expanded -->
<scheme name="PSExpanded">
<block start="/($()/" end="/())/" scheme="PowerShell" region00="def:PairStart" region10="def:PairEnd" region01="def:Var" region11="def:Var"/>

<!-- Array -->
<scheme name="PSArray">
<block start="/@(/" end="/)/" scheme="PowerShell" region00="def:PairStart" region10="def:PairEnd"/>

<!-- Hash -->
<scheme name="PSHash">
<block start="/@{/" end="/}/" scheme="PowerShell" region00="def:PairStart" region10="def:PairEnd"/>

<!-- Number -->
<entity name="psnumexp" value="(?:[eE][-+]?d+)"/>
<entity name="psnumsuf" value="([Ll]?(?:KB|MB|GB)?)"/>
<scheme name="PSNumber">
<regexp match="/B.?~1.d+%psnumexp;?%psnumsuf;b/i" region0="def:NumberFloat" region1="def:NumberSuffix"/>
<regexp match="/bd+..?!d*(?:%psnumexp;?%psnumsuf;b|B)/i" region0="def:NumberFloat" region1="def:NumberSuffix"/>
<regexp match="/bd+%psnumexp;%psnumsuf;b/i" region0="def:NumberFloat" region1="def:NumberSuffix"/>
<regexp match="/b0[xX][da-fA-F]+%psnumsuf;b/i" region0="def:NumberHex" region1="def:NumberSuffix"/>
<regexp match="/bd+%psnumsuf;b/i" region0="def:NumberDec" region1="def:NumberSuffix"/>

<!-- Content in '' -->
<scheme name="PSAposContent">
<regexp match="/''/" region="def:StringContent"/>

<!-- Content in "" -->
<scheme name="PSQuotContent">
<inherit scheme="PSEscaped"/>
<inherit scheme="PSVariable"/>
<inherit scheme="PSExpanded"/>

<!-- Content of output -->
<scheme name="PSOutputContent">
<regexp match="/^ERROR(?::|b)|<<<<(?:s|$)/" region="def:Error"/>
<regexp match="/^WARNINGb.*$/" region="def:StringContent"/>
<regexp match="/^(?:DEBUG|VERBOSE)b.*$/" region="def:Comment"/>
<inherit scheme="PSNumber"/>

<!-- Main -->
<scheme name="PowerShell">

<!-- Output -->
<block start="/^x1A$/" end="/^x1B$/" scheme="PSOutputContent" region00="def:PairStart" region10="def:PairEnd"/>

<!-- Comments -->
<regexp match="/(?:^|s)###s+(.*)/" region="def:Comment" region1="def:Outlined"/>
<regexp match="/(?:^|s)##.*/" region="def:CommentDoc"/>
<regexp match="/(?:^|s)#.*/" region="def:Comment"/>

<!-- Apos-strings -->
<block start="/@x27$/" end="/^x27@/" scheme="PSAposContent" region="def:String" region00="def:PairStart" region10="def:PairEnd"/>
<block start="/x27/" end="/x27/" scheme="PSAposContent" region="def:String" region00="def:PairStart" region10="def:PairEnd"/>

<!-- Escaped -->
<inherit scheme="PSEscaped"/>

<!-- Expanded -->
<inherit scheme="PSExpanded"/>

<!-- Array -->
<inherit scheme="PSArray"/>

<!-- Hash -->
<inherit scheme="PSHash"/>

<!-- Quot-strings -->
<block start="/@x22$/" end="/^x22@/" scheme="PSQuotContent" region="def:String" region00="def:PairStart" region10="def:PairEnd"/>
<block start="/x22/" end="/x22/" scheme="PSQuotContent" region="def:String" region00="def:PairStart" region10="def:PairEnd"/>

<!-- Types [], [xxx[]] except [1], [$i] -->
<regexp match="/[[A-Za-z][w.]*(?:[])*]/" region="def:TypeKeyword"/>

<!-- Brackets -->
<inherit scheme="def:PairedBrackets">
<virtual scheme="def:PairedBrackets" subst-scheme="PowerShell"/>

<!-- Function -->
<regexp match="/(?:^|~|[;}]?#1)s*(function|filter)s+([^s(]+)/i" region1="def:FunctionKeyword" region2="def:Identifier" region="def:Outlined"/>

<!-- Pipeline and redirection -->
<keywords ignorecase="yes" region="def:KeywordStrong">
<symb name="|"/>
<symb name="&gt;"/>
<symb name="&gt;&gt;"/>
<symb name="2&gt;"/>
<symb name="2&gt;&amp;1"/>
<symb name="2&gt;&gt;"/>

<!-- Redirection operators (not yet) -->
<keywords ignorecase="yes" region="def:Error">
<word name="&lt;"/>
<word name="1&gt;&amp;2"/>

<!-- Numbers -->
<inherit scheme="PSNumber"/>

<!-- Cmdlets -->
<keywords ignorecase="yes" region="def:Keyword" worddiv="[s(){};=|]">
<word name="Add-Content"/>
<word name="Add-History"/>
<word name="Add-Member"/>
<word name="Add-PSSnapin"/>
<word name="Clear-Content"/>
<word name="Clear-Host"/>
<word name="Clear-Item"/>
<word name="Clear-ItemProperty"/>
<word name="Clear-Variable"/>
<word name="Compare-Object"/>
<word name="ConvertFrom-SecureString"/>
<word name="Convert-Path"/>
<word name="ConvertTo-Html"/>
<word name="ConvertTo-SecureString"/>
<word name="Copy-Item"/>
<word name="Copy-ItemProperty"/>
<word name="Export-Alias"/>
<word name="Export-Clixml"/>
<word name="Export-Console"/>
<word name="Export-Csv"/>
<word name="ForEach-Object"/>
<word name="Format-Custom"/>
<word name="Format-List"/>
<word name="Format-Table"/>
<word name="Format-Wide"/>
<word name="Get-Acl"/>
<word name="Get-Alias"/>
<word name="Get-AuthenticodeSignature"/>
<word name="Get-ChildItem"/>
<word name="Get-Command"/>
<word name="Get-Content"/>
<word name="Get-Credential"/>
<word name="Get-Culture"/>
<word name="Get-Date"/>
<word name="Get-EventLog"/>
<word name="Get-ExecutionPolicy"/>
<word name="Get-Help"/>
<word name="Get-History"/>
<word name="Get-Host"/>
<word name="Get-Item"/>
<word name="Get-ItemProperty"/>
<word name="Get-Location"/>
<word name="Get-Member"/>
<word name="Get-PfxCertificate"/>
<word name="Get-Process"/>
<word name="Get-PSDrive"/>
<word name="Get-PSProvider"/>
<word name="Get-PSSnapin"/>
<word name="Get-Service"/>
<word name="Get-TraceSource"/>
<word name="Get-UICulture"/>
<word name="Get-Unique"/>
<word name="Get-Variable"/>
<word name="Get-WmiObject"/>
<word name="Group-Object"/>
<word name="Import-Alias"/>
<word name="Import-Clixml"/>
<word name="Import-Csv"/>
<word name="Invoke-Expression"/>
<word name="Invoke-History"/>
<word name="Invoke-Item"/>
<word name="Join-Path"/>
<word name="Measure-Command"/>
<word name="Measure-Object"/>
<word name="Move-Item"/>
<word name="Move-ItemProperty"/>
<word name="New-Alias"/>
<word name="New-Item"/>
<word name="New-ItemProperty"/>
<word name="New-Object"/>
<word name="New-PSDrive"/>
<word name="New-Service"/>
<word name="New-TimeSpan"/>
<word name="New-Variable"/>
<word name="Out-Default"/>
<word name="Out-File"/>
<word name="Out-Host"/>
<word name="Out-Null"/>
<word name="Out-Printer"/>
<word name="Out-String"/>
<word name="Pop-Location"/>
<word name="Push-Location"/>
<word name="Read-Host"/>
<word name="Remove-Item"/>
<word name="Remove-ItemProperty"/>
<word name="Remove-PSDrive"/>
<word name="Remove-PSSnapin"/>
<word name="Remove-Variable"/>
<word name="Rename-Item"/>
<word name="Rename-ItemProperty"/>
<word name="Resolve-Path"/>
<word name="Restart-Service"/>
<word name="Resume-Service"/>
<word name="Select-Object"/>
<word name="Select-String"/>
<word name="Set-Acl"/>
<word name="Set-Alias"/>
<word name="Set-AuthenticodeSignature"/>
<word name="Set-Content"/>
<word name="Set-Date"/>
<word name="Set-ExecutionPolicy"/>
<word name="Set-Item"/>
<word name="Set-ItemProperty"/>
<word name="Set-Location"/>
<word name="Set-PSDebug"/>
<word name="Set-Service"/>
<word name="Set-TraceSource"/>
<word name="Set-Variable"/>
<word name="Sort-Object"/>
<word name="Split-Path"/>
<word name="Start-Service"/>
<word name="Start-Sleep"/>
<word name="Start-Transcript"/>
<word name="Stop-Process"/>
<word name="Stop-Service"/>
<word name="Stop-Transcript"/>
<word name="Suspend-Service"/>
<word name="Tee-Object"/>
<word name="Test-Path"/>
<word name="Trace-Command"/>
<word name="Update-FormatData"/>
<word name="Update-TypeData"/>
<word name="Where-Object"/>
<word name="Write-Debug"/>
<word name="Write-Error"/>
<word name="Write-Host"/>
<word name="Write-Output"/>
<word name="Write-Progress"/>
<word name="Write-Verbose"/>
<word name="Write-Warning"/>

<!-- System variables -->
<keywords ignorecase="yes" region="def:Constant">
<word name="$$"/>
<word name="$?"/>
<word name="$^"/>
<word name="$_"/>
<word name="$args"/>
<word name="$ConfirmPreference"/>
<word name="$ConsoleFileName"/>
<word name="$DebugPreference"/>
<word name="$Error"/>
<word name="$ErrorActionPreference"/>
<word name="$ErrorView"/>
<word name="$ExecutionContext"/>
<word name="$false"/>
<word name="$FormatEnumerationLimit"/>
<word name="$HOME"/>
<word name="$Host"/>
<word name="$input"/>
<word name="$LastExitCode"/>
<word name="$Matches"/>
<word name="$MaximumAliasCount"/>
<word name="$MaximumDriveCount"/>
<word name="$MaximumErrorCount"/>
<word name="$MaximumFunctionCount"/>
<word name="$MaximumHistoryCount"/>
<word name="$MaximumVariableCount"/>
<word name="$MyInvocation"/>
<word name="$NestedPromptLevel"/>
<word name="$null"/>
<word name="$OFS"/>
<word name="$PID"/>
<word name="$PROFILE"/>
<word name="$ProgressPreference"/>
<word name="$PSHOME"/>
<word name="$PWD"/>
<word name="$ReportErrorShowExceptionClass"/>
<word name="$ReportErrorShowInnerException"/>
<word name="$ReportErrorShowSource"/>
<word name="$ReportErrorShowStackTrace"/>
<word name="$ShellId"/>
<word name="$this"/>
<word name="$true"/>
<word name="$VerbosePreference"/>
<word name="$WarningPreference"/>
<word name="$WhatIfPreference"/>

<!-- User variables -->
<inherit scheme="PSVariable"/>

<!-- Operators -->
<keywords ignorecase="yes" region="def:Operator">
<word name="-eq"/>
<word name="-ne"/>
<word name="-ge"/>
<word name="-gt"/>
<word name="-lt"/>
<word name="-le"/>
<word name="-like"/>
<word name="-notlike"/>
<word name="-match"/>
<word name="-notmatch"/>
<word name="-replace"/>
<word name="-contains"/>
<word name="-notcontains"/>
<word name="-ieq"/>
<word name="-ine"/>
<word name="-ige"/>
<word name="-igt"/>
<word name="-ile"/>
<word name="-ilt"/>
<word name="-ilike"/>
<word name="-inotlike"/>
<word name="-imatch"/>
<word name="-inotmatch"/>
<word name="-ireplace"/>
<word name="-icontains"/>
<word name="-inotcontains"/>
<word name="-ceq"/>
<word name="-cne"/>
<word name="-cge"/>
<word name="-cgt"/>
<word name="-clt"/>
<word name="-cle"/>
<word name="-clike"/>
<word name="-cnotlike"/>
<word name="-cmatch"/>
<word name="-cnotmatch"/>
<word name="-creplace"/>
<word name="-ccontains"/>
<word name="-cnotcontains"/>
<word name="-is"/>
<word name="-isnot"/>
<word name="-as"/>
<word name="-and"/>
<word name="-not"/>
<word name="-or"/>
<word name="-xor"/>
<word name="-band"/>
<word name="-bor"/>
<word name="-bxor"/>
<word name="-f"/>
<symb name="--"/>
<symb name="++"/>
<symb name="+="/>
<symb name="-="/>
<symb name="*="/>
<symb name="/="/>
<symb name="%="/>
<symb name="="/>
<symb name="+"/>
<symb name="*"/>
<symb name="/"/>
<symb name="%"/>

<!-- Operator - -->
<regexp match="/-[A-Za-z_]?!/" region="def:Operator"/>

<!-- Keywords (filter and function are excluded) -->
<keywords ignorecase="yes" region="def:Keyword" worddiv="[s(){};]">
<word name="begin"/>
<word name="break"/>
<word name="continue"/>
<word name="default"/>
<word name="do"/>
<word name="else"/>
<word name="elseif"/>
<word name="end"/>
<word name="exit"/>
<word name="finally"/>
<word name="for"/>
<word name="foreach"/>
<word name="if"/>
<word name="in"/>
<word name="param"/>
<word name="process"/>
<word name="return"/>
<word name="switch"/>
<word name="throw"/>
<word name="trap"/>
<word name="until"/>
<word name="while"/>

<!-- Identifiers (very simplified) -->
<regexp match="/[A-Za-z_][-w]*/" region="def:Identifier"/>

<!-- Error: (ok, warning): redundant semicolon -->
<regexp match="/;s*}?(?:s*|s+#.*)$/" region="def:Error"/>

<!-- Error: bad string: symbols after @' or @" -->
<regexp match="/@[x22x27].$/" region="def:Error"/>

<!-- Separators -->
<regexp match="/[,;]/" region="def:Operator"/>



<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
- The Original Code is the Colorer Library.
- The Initial Developer of the Original Code is
- Cail Lomecb <>.
- Portions created by the Initial Developer are Copyright (C) 1999-2005
- the Initial Developer. All Rights Reserved.
- Contributor(s):
- Roman Kuzmin <>
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the LGPL or the GPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
- ***** END LICENSE BLOCK ***** -->


Resize-Console.ps1 – Resize console window/buffer using arrow keys


Perhaps resizing of Windows console is quite tricky. This script makes it easy with arrow keys.


## Author   : Roman Kuzmin
## Synopsis : Resize console window/buffer using arrow keys

function Size($w, $h)
    New-Object System.Management.Automation.Host.Size($w, $h)

Write-Host '[Arrows] resize  [Esc] exit ...'
$ErrorActionPreference = 'SilentlyContinue'
for($ui = $Host.UI.RawUI;;) {
    $b = $ui.BufferSize
    $w = $ui.WindowSize
    switch($ui.ReadKey(6).VirtualKeyCode) {
        37 {
            $w = Size ($w.width - 1) $w.height
            $ui.WindowSize = $w
            $ui.BufferSize = Size $w.width $b.height
        39 {
            $w = Size ($w.width + 1) $w.height
            $ui.BufferSize = Size $w.width $b.height
            $ui.WindowSize = $w
        38 {
            $ui.WindowSize = Size $w.width ($w.height - 1)
        40 {
            $w = Size $w.width ($w.height + 1)
            if ($w.height -gt $b.height) {
                $ui.BufferSize = Size $b.width $w.height
            $ui.WindowSize = $w
        27 {

1 Comment

Format-Chart.ps1 – Formats output as a table with a chart column


The script formats output as a table with a pseudo-graphical chart column calculated for the last specified numeric property.


# Chart of process working sets
ps | Format-Chart Id, Name, WS

# Chart of file sizes in descending order
dir | sort Length -desc | Format-Chart Name, Length


## Author   : Roman Kuzmin
## Synopsis : Formats output as a table with a chart column
## Modified : 2006.11.06
## -Property: properties where the last one is numeric for a chart.
## -Width: chart column width, default is 1/2 of screen buffer.
## -ForeChar: character for chart bars.
## -BackChar: character for appending bars.
## -InputObject: the objects to be formatted.

    [object[]]$Property = $(throw 'Supply properties'),
    [int]$Width = ($Host.UI.RawUI.BufferSize.Width/2),
    [char]$ForeChar = 9600,
    [char]$BackChar = 9617,

$set = $(if ($InputObject) {$InputObject} else {@($Input)}) |
Select-Object $Property

$max = ($set | Measure-Object ($Property[-1]) -Maximum).Maximum
if ($max -eq 0) {$max = 1}

$set | .{process{
    $_ | Add-Member -PassThru NoteProperty Chart (("$ForeChar"*(
    $_.$($Property[-1])/$max*$Width)).PadRight($Width, $BackChar))
}} |
Format-Table ($Property + 'Chart') -AutoSize

Leave a comment