If you’d like to make sure a folder content stays untouched, you can use catalog files. A catalog file lists all folder content plus creates hashes for each file in the folder. Here is an example:

# path to folder to create a catalog file for
# (make sure it exists and isn't too large)
$path = "$Home\Desktop"
# path to catalog file to be created
$catPath = "$env:temp\myDesktop.cat"
# create catalog
New-FileCatalog -Path $path -CatalogVersion 2.0 -CatalogFilePath $catPath

Depending on how large the folder is, it may take some time to create the catalog file. You cannot create catalogs for files that are locked and in use. The resulting catalog file is a binary file that contains the hashes of all files in your folder.

To check whether the folder is still untouched, you can use Test-FileCatalog:

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


Status        : Valid
HashAlgorithm : SHA256
CatalogItems  : {...}
PathItems     : {...}
Signature     : System.Management.Automation.Signature 
 

If folder content and catalog match, then the result status is “Valid”. Else, the CatalogItems property contains a detailed list of all folder items, and whether they are still untouched or have changed.


psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU - with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!

Anonymous