Archive for December, 2006

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 ***** -->