Created
May 15, 2019 11:53
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This script retrieves SQL Server version from BAK file and allows you to compare with your SQL Server version | |
#If your SQL Server version is lower that one which was used to create backup you won't be able to restore BAK file | |
$BakFile= Read-Host "Provide full path to SQL BAK file (including file name with extension)" | |
$VerDetectQuery="RESTORE HEADERONLY FROM DISK='$BakFile'" | |
$BakMajorVer=Invoke-Sqlcmd -Query $VerDetectQuery | Select-Object -ExpandProperty SoftwareVersionMajor | |
$BakMinorVer=Invoke-Sqlcmd -Query $VerDetectQuery | Select-Object -ExpandProperty SoftwareVersionMinor | |
$BakBuildVer=Invoke-Sqlcmd -Query $VerDetectQuery | Select-Object -ExpandProperty SoftwareVersionBuild | |
$BakVer= "$BakMajorVer.$BakMinorVer.$BakBuildVer.0" | |
$ServerSQLVer=Invoke-Sqlcmd -Query "SELECT SERVERPROPERTY('productversion')" | Select-Object -ExpandProperty Column1 | |
Write-Host "Backup file SQL Server version is: " $BakVer | |
Write-Host "Your SQL Server version is: " $ServerSQLVer | |
If ($BakVer -le $ServerSQLVer) | |
{ | |
Write-Host "You can restore this backup on your server" -BackgroundColor Green | |
} | |
Else | |
{ | |
Write-Host "You cannot restore backup on your server, to be able to do that you need to upgrade SQL Server version" -BackgroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment