Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Last active January 23, 2025 23:40
Show Gist options
  • Save TiloGit/eed089c56aa1aa07d060d46294b0cbdc to your computer and use it in GitHub Desktop.
Save TiloGit/eed089c56aa1aa07d060d46294b0cbdc to your computer and use it in GitHub Desktop.
Read IBM FileNet GCD from Database as XML script
$SQLServer = "mysqlserver1232.westus2.cloudapp.azure.com"
$SQLDBName = "ABC_FNGCD"
$uid ="sa"
$pwd = "my-db-pass123"
##modify below query if you want specific GCD version
$SqlQuery = "select gcd_blob FROM FNGCD WHERE epoch_id = (select last_epoch_id from FNGCD where epoch_id = 0);"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; User ID = $uid; Password = $pwd;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables
$instream = [System.IO.MemoryStream]::new($DataSet.Tables.gcd_blob)
$zlib = [System.IO.Compression.ZLibStream]::new(
$instream,
[System.IO.Compression.CompressionMode]::Decompress)
$outstream = [System.IO.MemoryStream]::new()
$zlib.CopyTo($outstream)
$zlib.Dispose()
# Choose encoding here
$enc = [System.Text.Encoding]::UTF8
##out to console
$enc.GetString($outstream.ToArray())
##out to XML file
$enc.GetString($outstream.ToArray()) | out-file my-gcd.xml -encoding utf8
@TiloGit
Copy link
Author

TiloGit commented Jan 23, 2025

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