Using Catalog Files

by Nov 26, 2018

Catalog file support (.cat) is new in PowerShell 5.1. Cat files basically are file lists with hash values. You can use them to ensure that a given file structure is unchanged.

Here is a simple example. It takes a folder (make sure it exists, or else rename it) and creates a cat file for the entire folder content. Note that this involves creating a hash value for each file in the folder, so keep an eye on a reasonable folder size:

$path = c:\folderToCheck"
$catPath = "$home\Desktop\"
New-FileCatalog -Path $path -CatalogVersion 2.0 -CatalogFilePath $catPath

New-FileCatalog creates a file on your desktop. This file can then be used to test the folder structure and make sure no file has changed:

Test-FileCatalog -Detailed -Path $path -CatalogFilePath $catPath

The result may look similar to this:

Status        : Valid
HashAlgorithm : SHA1
CatalogItems  : {[remoting systeminventar.ps1, 
                F43C8D6F9CB93FB9AA5DBA6733D9996645832256], [klonen und 
                prozessprio.ps1, F3DE20424CD90CDB5B85933B777A2F9A3F3D3187], 
                [scriptblock rueckgabewerte.ps1, 
                EB239D7906EF42E2639CACBE68C6FDD8F4AD899F], [Untitled4.ps1, 
PathItems     : {[beispielsyntax.ps1, 
                5183C82B7F0F3D0623242DD5F97A658724BE3B81], [closure.ps1, 
                D2A036B068548B3E773E3BEBCF40997231576ED1], [debug1.ps1, 
                3547D2659792A9ABA9E6E12F287D7A8116540FCF], [debug2.ps1, 
Signature     : System.Management.Automation.Signature 

Note that New-FileCatalog does not currently support special characters in file paths such as German “Umlaute”.

Twitter This Tip! ReTweet this Tip!