PowerShell Script To Get Timestamps of Nested file

2019-08-17 19:21发布

问题:

Our DBA has set backups of website databases to every 4 hours. The backup of each website database is created every 4 hours and it contains 4 files (with .bak) extension. Folder hierarchy of these backup files are as follows:

\\folder\sub-folder(4 X Files).bak

The problem we have is that we have to check in each "sub-folder" if the 4 (four) .bak files are created after every four 4 hours manually.

Can somebody help with the creation of a PowerShell script that can:

  • Generate the list of the web sites (subfolder name) in which 4 new files are not created for the latest timestamp.
  • Email us the list.

Following is the script I am using for this but it only gives part of the required stuff:

$folder = 'B:\sub-folder\Catfish_test'

$Clients = Import-Csv C:\test\backups.csv

$Files = Get-ChildItem $folder -Recurse -Include @("*.bak") |
         Where-Object {($_.CreationTime -gt (Get-Date).Date)} |
         select name 

$Clients | ForEach-Object {
    $Client = $_
    $ClientCheck = $Files | Where-Object {$_ -like $Client}
    if (-not $ClientCheck) { 
        Write-Warning "$Client is missing!"
    } else {
        Write-Output $ClientCheck
    }
} | Out-File C:\test\result.txt