$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = 'Server=REJK-P-SQL003\SQL01;Database=BCM;Trusted_Connection=True;'
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = 'SELECT [XmlDocumentContent] FROM eod.ObjXmlDocument xd WITH (NOLOCK) WHERE [XmlDocumentID] = 12660'
$result = $command.ExecuteReader()
$result.Read()
$blob = New-Object Byte[] ($result.GetBytes(0, 0, $null, 0, [int]::MaxValue))
$result.GetBytes(0, 0, $blob, 0, $blob.Length)
$filestream = New-Object System.IO.FileStream 'C:\users\ewpmni\desktop\sqlblob.zip', ([System.IO.FileMode]::Create), ([System.IO.FileAccess]::Write)
$filestream.Write($blob, 0, $blob.Length)
$filestream.Close()
$command.Dispose()
$connection.Close()