Requirement: We got a reuirement to validate all the SQL DB backups in specific location (local (or) remote)


Script Description: Generate HEADERONLY script for all DB backup files (*.bak), that are residing on particular location (including backups in sub folders)

 

Usage

1. open Powershell ISE console [ can save as file ].

2. Copy & past complete script mentioned in below script block

3. make sure you enter the directory of DB backups are residing (SQL Backup file with path (Local (or) remote path) to $path value

4. Execute

PowerShell
Edit|Remove
Clear-Host 
 
#Enter the path of Back files residing directory 
$path = "" 
 
 
Get-ChildItem -Recurse -Force -Path $path ` 
    | Where-Object {$_.Extension -like "*.bak"} ` 
    | Select-Object Fullname | ForEach-Object { 
"RESTORE HEADERONLY FROM DISK = '$($_.FullName)' 
GO" 
        }