Skip to content

Instantly share code, notes, and snippets.

@pnmcosta
Created August 27, 2019 14:48
Show Gist options
  • Save pnmcosta/fea74016525178c7c4e7503d223b78d7 to your computer and use it in GitHub Desktop.
Save pnmcosta/fea74016525178c7c4e7503d223b78d7 to your computer and use it in GitHub Desktop.
PS script to compute a new file hash for a modified BACPAC
param (
[string]$fileName = "model.xml"
)
If (Test-Path $fileName) {
$modelXmlPath = Resolve-Path $fileName
} else {
Write-Host ("File " + (Resolve-Path .) + "\" + $fileName + " does not exist");
exit;
}
Write-Host ("Creating hash for file: " + $modelXmlPath)
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create("System.Security.Cryptography.SHA256CryptoServiceProvider")
$fileStream = new-object System.IO.FileStream ` -ArgumentList @($modelXmlPath, [System.IO.FileMode]::Open)
$hash = $hasher.ComputeHash($fileStream)
$hashString = ""
Foreach ($b in $hash) { $hashString += $b.ToString("X2") }
$fileStream.Close()
Write-Host ("Hash is: " + $hashString)
@pnmcosta
Copy link
Author

Original script from: https://techcommunity.microsoft.com/t5/Azure-Database-Support-Blog/Editing-a-bacpac-file/ba-p/368931 modified to accept a -fileName parameter and resolve it properly, even from the uncompressed BACPAC package directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment