• Are you in for some Powershell ?

    I am using Quests free PowerGUI and this works like a charm !

    You will have to download and copy/paste Chad Miller's great Invoke-SQLCMD2 from Downloaded from: http://gallery.technet.microsoft.com/ScriptCenter/7985b7ef-ed89-4dfd-b02a-433cc4e30894/

    Paste it where I indicated in this following script

    <# Export FileStreamData to folder

    ALZDBA

    # http://www.sqlservercentral.com/Forums/Topic1173159-391-1.aspx?

    #>

    #######################

    <# Downloaded Invoke-Sqlcmd2 from: http://gallery.technet.microsoft.com/ScriptCenter/7985b7ef-ed89-4dfd-b02a-433cc4e30894/

    #>

    COPY/PASTE THE FUNCTION HERE function Invoke-Sqlcmd2 {....}

    } #Invoke-Sqlcmd2

    # This is the actual active code, just using Invoke-Sqlcmd2 to fetch the data

    ####################################################

    Clear-Host

    $tb = Invoke-Sqlcmd2 -ServerInstance YourSQLInstance -Database Adventureworks2008 -Query 'Select FileName, Document from [Production].[Document] where document is not null ' -as 'DataTable'

    #$tb.rows.count

    for ($i=0;$i -lt $tb.rows.count;$i++) {

    $TheDoc = $tb.Rows[$i].Document

    $TargetFile = $('c:\temp\BU\{0}' -f $tb.Rows[$i].FileName )

    #$TheDoc.Length

    [System.IO.File]::WriteAllBytes($TargetFile,$TheDoc)

    }

    Write-Host $("[{0}] documents exported" -f $tb.rows.count )

    Maybe someone can enhance it using a SQLDatareader, but I just wanted to post a working script at this time. :Whistling:

    It uses a datatable, which is known to be slower then a datareader object :blush:

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me