PowerShell Genie

Check whether recent backup files arrived

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

List the twenty newest files written to a backup folder in the last day; use this as an arrival check, not proof of recoverability.

Example reviewed 1 October 2026 · Illustrative output · Not a live system check

The script

$BackupPath = 'D:\Backups'
$ExpectedSince = (Get-Date).AddDays(-1)
Get-ChildItem -LiteralPath $BackupPath -File -ErrorAction Stop |
    Where-Object LastWriteTime -ge $ExpectedSince |
    Sort-Object LastWriteTime -Descending |
    Select-Object -First 20 Name, Length, LastWriteTime

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output

    Fictional reference snapshot · 03 October 2026, 09:00 UTC. This is an example result, not a check of your systems.

    Name                       Length      LastWriteTime
    ----                       ------      -------------
    training-20261003.zip       104857600   03/10/2026 03:10:00
    training-20261002.zip       103809024   02/10/2026 22:00:00
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    $BackupPath = 'D:\Backups' $ExpectedSince = (Get-Date).AddDays(-1) Get-ChildItem -LiteralPath $BackupPath -File -ErrorAction Stop | Where-Object LastWriteTime -ge $ExpectedSince | Sort-Object LastWriteTime -Descending | Select-Object -First 20 Name, Length, LastWriteTime
    1. Stage 1$BackupPathPositional values or no named parameters
    2. Stage 2Where-Object-ge
    3. Stage 3Sort-Object-Descending
    4. Stage 4Select-Object-First

      Illustrative output

      This example shows the expected shape for fictional data. Your values and formatting will differ.

      Name            Length     LastWriteTime
      nightly-01.bak  104857600  2026-10-01 01:00:00
      nightly-02.bak  52428800   2026-09-30 23:30:00

      How it works

      The pipeline filters by timestamp, sorts newest first and then limits the result. Its output contains Name, Length and LastWriteTime in that order. The fictional timestamps assume a run on 1 October 2026 at 09:00.

      Before you run it

      Read access to the local folder or share is required. Use the expected time window for your backup job. The example does not recurse into subfolders.

      Check the result

      Check expected file names, counts, sizes and job logs. Confirm integrity and periodically test restore procedures. A recent nonempty file can still be incomplete or unusable.

      If nothing is returned

      No file matched the time window at the top level. Confirm the path, permissions, clock and job schedule before deciding the backup is missing.

      Practise the underlying skill

      Try a related exercise →

      Read the primary Microsoft documentation

      Genie guideCheck whether recent backup files arrived

      List the twenty newest files written to a backup folder in the last day; use this as an arrival check, not proof of recoverability.