PoshCode Archive  Artifact [4392ac0d4c]

Artifact 4392ac0d4c7110b06117186ad767ac1fb683192badb8a938bef888b4887b7eaf:

  • File Monitor-folders.ps1 — part of check-in [1985b457d0] at 2018-06-10 14:06:48 on branch trunk — Compare files in multiple folders against a reference set to provide an early detection of Cryptolocker (user: dfsdiag size: 1409)

# encoding: ascii
# api: powershell
# title: Monitor folders
# description: Compare files in multiple folders against a reference set to provide an early detection of Cryptolocker
# version: 0.1
# author: dfsdiag
# license: CC0
# x-poshcode-id: 6042
# x-archived: 2016-05-17T12:52:46
# x-published: 2016-10-08T10:46:00
#
#
# TXT File containing the server hostnames or IPs you want to monitor
$monitoredServers = gc "C:\ServersToMonitor.txt"
# Directory containing the folder structure you want to compare
$referenceDirectory = "C:\CLEAN\"

# Get a list of files including the relative folder structure
$monitoredFiles = gci -Recurse $referenceDirectory | ? { ! $_.PSIsContainer } | % { $($_.FullName).replace("$referenceDirectory","") }

# Iterate through the list of servers
foreach ($server in $monitoredServers) {
    Write-Host "Checking: $server" -ForegroundColor GREEN
    
    # Iterate through  all the files found in the reference directory
    foreach ($file in $monitoredFiles) {
        Write-Host "Checking: \\$server\$file against $referenceDirectory\$file"
        
        # Check if the file exists and if it's contents match the reference files
        if ((!(Test-Path "\\$server\$file")) -or (Compare-Object $(gc "\\$server\$file") $(gc $referenceDirectory\$file))) {
               Write-Host "FILES DO NOT MATCH" -ForegroundColor RED
        }
    }
}