Also, if you would like to use this in PowerShell just execute the following to create a new object type
Add-Type -TypeDefinition @"
using System;
using System.IO;
public class GetSQLBackup
{
public static int getDbVersion(string backupFilePath)
{
FileStream f = new FileStream(backupFilePath, FileMode.Open);
byte[] b = new byte[2];
f.Seek(3756, SeekOrigin.Begin);
b[0] = (byte)f.ReadByte();
b[1] = (byte)f.ReadByte();
Int16 dbVersion = BitConverter.ToInt16(b, 0);
f.Close();
return dbVersion;
}
}
"@
After executing this you can call it like this:
[GetSQLBackup]::getDbVersion("C:\\SQLBackups\\YourBackupFile.bak")