Skip to content

Instantly share code, notes, and snippets.

@bseebacher
Last active September 26, 2017 02:39
Show Gist options
  • Save bseebacher/b20c30e401ba8c5aeceb00d61172f690 to your computer and use it in GitHub Desktop.
Save bseebacher/b20c30e401ba8c5aeceb00d61172f690 to your computer and use it in GitHub Desktop.
Example of writing varbinary(MAX) return of [catalog].[get_project] to file.
$cmdExport = New-Object System.Data.SqlClient.SqlCommand
$cmdExport.Connection = $catalogDbConnection # Open connection to SSISDB
$cmdExport.CommandText = "[catalog].[get_project]"
$cmdExport.Parameters.AddWithValue("@folder", "<your SSIS Folder Name>") | Out-Null
$cmdExport.Parameters.AddWithValue("@project", "<your SSIS Project Name") | Out-Null
# Use ExecuteScalar() method to get a cursor to read varbinary(MAX) return.
$bReader = $sqlCommand.ExecuteScalar()
# WRITING OUTPUT
# Use the WriteAllBytes static method on the .NET System.IO.File class
# for writing bytes to disk at provided path.
# Cast varbinary(MAX) query return to byte[] array to use as function argument.
[System.IO.File]::WriteAllBytes("SsisPackage.zip", [byte[]]$bReader) | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment