(view source code of airregccmd.ps as plain text)
<#.SYNOPSISSearch a downloaded Canadian Civil Aircraft Register database for an aircraft registation and if found, return the aircraft manufacturer and model (tab-delimited).DESCRIPTIONFirst, create a subdirectory 'C' in this script's parent folder.Next, download the Canadian Civil Aircraft Register database (see links section), unzip it and move the file carscurr.txt (and optionally the other files as well) to the 'C' folder.Now run this script with an aircraft registration as its only parameter (see examples section).The script will first look for the specified registration code in column 1 of the carscurr.txt file.If a match is found, the manufacturer and model are found in columns 4 and 5.The script will display a tab-delimited string with the registration, the manufacturer and the aircraft model (<registration><tab><manufacturer><tab><model>).If the script was started by another PowerShell script, the calling PowerShell script may also read the manufacturer and model from the variables $Manufacturer and $Model, passed on by this script.If the script was started by a batch file, the calling batch file can use 'FOR /F' on this PowerShell script's screen output to find the manufacturer and model.Get-Help './AirRegCCmd.ps1' -Examples will show 2 examples of this script being called by another script.The script contains a "second" script in a comment block, showing the "official' way to deal with the database's CSV files; however, the method used, regular expressions on plain text files, is about 4 times faster..PARAMETER RegistrationA valid Canadian aircraft registration, i.e. C-xxx or C-xxxx (where each x is a single alphanumeric character/digit).PARAMETER QuietIgnore all errors and do not display any error messages; in case of errors, just terminate with return code 1..PARAMETER HelpShow the script's help screen.PARAMETER DebugShow some progress messages.OUTPUTSA tab-delimited string <registration><tab><manufacturer><tab><model> and manufacturer and model are also stored in output variables $Manufacturer and $Model..EXAMPLE. ./AirRegCCmd.ps1 "C-AHA"Will return tab-delimited string "N1944S<tab>BOEING<tab>E75N1", and set variables $Manufacturer to "BOEING" and $Model to "E75N1".EXAMPLE"C-AHA" | . ./AirRegCCmd.ps1Will also return tab-delimited string "N1944S<tab>BOEING<tab>E75N1", and set variables $Manufacturer to "BOEING" and $Model to "E75N1".EXAMPLE. ./AirRegCCmd.ps1 "C-AHA" -DebugThis will return:Start searching AHA in carscurr.txt file at <date> <time>C-AHA Boeing E75N1Finished at <date> <time> (elapsed time <time elapsed>).EXAMPLECreate and run the following PowerShell script:===============================================================$Registration = 'C-AHA' ; $Manufacturer = '' ; $Model = ''[void] ( . "$PSScriptRoot\AirRegCCmd.ps1" -Registration $Registration )Write-Host ( "Registration : {0}`nManufacturer : {1}`nModel : {2}" -f $Registration, $Manufacturer, $Model )===============================================================Besides setting variables $Manufacturer to "BOEING" and $Model to "E75", it will return:Registration : C-AHAManufacturer : BOEINGModel : E75N1.EXAMPLECreate and run the following batch file:===============================================================REM Note that there should only be a TAB and nothing else between delims= and the doublequoteFOR /F "tokens=1-3 delims= " %%A IN ('powershell . ./AirRegCCmd.ps1 C-AHA') DO ( ECHO Registration : %%A ECHO Manufacturer : %%B ECHO Model : %%C)===============================================================It will return:Registration : C-AHAManufacturer : BOEINGModel : E75N1.LINKScript written by Rob van der Woude:https://www.robvanderwoude.com/.LINKCanadian Civil Aircraft Register database:https://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx.LINKCapture -Debug parameter by mklement0 on StackOverflow.com:https://stackoverflow.com/a/48643616#>param (
[parameter( ValueFromPipeline )]
[ValidatePattern("(^\s*$|[\?/-]|^C-[A-Z]{3,4}$)")]
[string]$Registration,
[switch]$Quiet,
[switch]$Help
)$progver = "1.00"
$Registration = $Registration.ToUpper( )
[string]$Manufacturer = ''
[string]$Model = ''
[bool]$Debug = ( $PSBoundParameters.ContainsKey( 'Debug' ) )
function ShowHelp( $errormessage = '' ) {
if ( !$Quiet ) {
if ( $errormessage ) {
Write-HostWrite-Host "Error: " -ForegroundColor Red -NoNewline
Write-Host $errormessage
} Write-HostWrite-Host ( "AirRegCCmd.ps1, Version {0}" -f $progver )
Write-Host "Search downloaded Canadian Civil Aircraft Register database for a registation"
Write-HostWrite-Host "Usage: " -NoNewline
Write-Host ". ./AirRegCCmd.ps1 [-Registration] C-*** [-Quiet] [-Debug] [-Help]" -ForegroundColor White
Write-HostWrite-Host "Where: " -NoNewline
Write-Host "C-*** " -NoNewline -ForegroundColor White
Write-Host "is a valid Canadian aircraft registration, e.g. C-AHA"
Write-Host " -Quiet " -NoNewline -ForegroundColor White
Write-Host "all errors are ignored and no error messages displayed"
Write-Host " -Debug " -NoNewline -ForegroundColor White
Write-Host "shows some progress messages"
Write-Host " -Help " -NoNewline -ForegroundColor White
Write-Host "shows this help screen"
Write-HostWrite-Host "Notes: This script requires a downloaded Canadian Civil Aircraft Register"
Write-Host " database, located in a subfolder 'C' of this script's parent folder."
Write-Host " The Canadian Civil Aircraft Register database can be downloaded at:"
Write-Host " https://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx" -ForegroundColor DarkGray
Write-Host " The result, if any, of the search is displayed as tab-delimited text:"
Write-Host " <registration><tab><manufacturer><tab><model>"
Write-Host " Besides its screen output, this script will also set the `$Manufacturer"
Write-Host " and `$Model variables with the database search result."
Write-Host " Run " -NoNewline
Write-Host "Get-Help `"./AirRegCCmd.ps1`" -Examples " -NoNewline -ForegroundColor White
Write-Host "for some examples of"
Write-Host " `"nesting`" this script in other PowerShell or batch scripts."
Write-Host " Return code (`"ErrorLevel`") 1 in case of errors, otherwise 0."
Write-HostWrite-Host "Credits: Code to capture -Debug parameter by mklement0 on StackOverflow.com:"
Write-Host " https://stackoverflow.com/a/48643616" -ForegroundColor DarkGray
Write-HostWrite-Host "Written by Rob van der Woude"
Write-Host "https://www.robvanderwoude.com"
} exit 1}if ( $Help -or $Registration -match '(^\s*$|[\?/])' ) {
ShowHelp
exit 1}$C_number = $Registration.Substring( 2 )
$dbfolder = ( Join-Path -Path $PSScriptRoot -ChildPath 'C' )
$dbfile = ( Join-Path -Path $dbfolder -ChildPath 'carscurr.txt' )
if ( Test-Path -Path $dbfile -PathType 'Leaf' ) {
if ( $Debug ) {
$StopWatch = [system.diagnostics.stopwatch]::StartNew( )
Write-Host ( "Start searching {0} in carscurr.txt file at {1}" -f $C_number, ( Get-Date ) )
}$pattern = '^\"{0,4}\",[^\n\r]+' -f $C_number
$record = ( ( Get-Content -Path $dbfile ) -match $pattern )
if ( $record ) {
$Manufacturer = ( $record.Split( ',' )[3] -replace '(^\"|\s*\")','' )
$Model = ( $record.Split( "," )[4] -replace '(^\"|\s*\")','' )
}"{0}`t{1}`t{2}" -f $Registration.ToUpper( ), $Manufacturer, $Model | Out-String
if ( $Debug ) {
Write-Host ( "Finished at {0} (elapsed time {1})`n`n" -f ( Get-Date ), $StopWatch.Elapsed )
$StopWatch.Stop( )
}} else {
if ( $Quiet ) {
if ( $Debug ) {
Write-Host ( "Downloaded Canadian Civil Aircraft Register database file `"{0}`" not found" -f $dbfile )
} exit 1} else {
$message = "No downloaded Canadian Civil Aircraft Register database was found.`n`nDo you want to open the download webpage for the database now?"
$title = 'No Database Found'
$buttons = 'YesNo'
Add-Type -AssemblyName System.Windows.Forms
$answer = [System.Windows.Forms.MessageBox]::Show( $message, $title, $buttons )
if ( $answer -eq "Yes" ) {
$url = 'https://wwwapps.tc.gc.ca/Saf-Sec-Sur/2/CCARCS-RIACC/DDZip.aspx'
Start-Process $url
} else {
ShowHelp( 'No downloaded Canadian Civil Aircraft Register database found, please download it and try again' )
} }}page last modified: 2025-10-11; loaded in 0.0097 seconds