commands

^

Export-DbaBinaryFile

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Export-DbaBinaryFile on GitHub.
Want to see the Bill Of Health for this command? Check out Export-DbaBinaryFile.

Synopsis

Exports binary files from SQL Server

Description

Exports binary files from SQL Server

If specific filename and binary columns aren't specified, the command will guess based on the datatype (binary/image) for the binary column and a match for "name" as the filename column.

Syntax

Export-DbaBinaryFile
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-Table] <String[]>]
    [[-Schema] <String[]>]
    [[-FileNameColumn] <String>]
    [[-BinaryColumn] <String>]
    [[-Path] <String>]
    [[-Query] <String>]
    [[-FilePath] <String>]
    [[-InputObject] <Table[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Export-DbaBinaryFile -SqlInstance sqlcs -Database test -Path C:\temp\exports

Exports all binary files from the test database on sqlcs to C:\temp\exports. Guesses the columns based on datatype and column name.

Example: 2
PS C:\> Export-DbaBinaryFile -SqlInstance sqlcs -Database employees -Table photos  -Path C:\temp\exports

Exports all binary files from the photos table in the employees database on sqlcs to C:\temp\exports. Guesses the columns based on datatype and column name.

Example: 3
PS C:\> Export-DbaBinaryFile -SqlInstance sqlcs -Database employees -Table photos -FileNameColumn fname -BinaryColumn data -Path C:\temp\exports

Exports all binary files from the photos table in the employees database on sqlcs to C:\temp\exports. Uses the fname and data columns for the filename and binary data.

Example: 4
PS C:\> Export-DbaBinaryFile -SqlInstance sqlcs -Database employees -Table photos -Query "SELECT [FileName], [Data] FROM [employees].[dbo].[photos] WHERE FirstName = 'Potato' and LastName =

'Qualitee'" -FilePath C:\temp\PotatoQualitee.jpg
Exports the binary file from the photos table in the employees database on sqlcs to C:\temp\PotatoQualitee.jpg. Uses the query to determine the filename and binary data.

Example: 5
PS C:\> Get-DbaBinaryFileTable -SqlInstance sqlcs -Database test | Out-GridView -Passthru | Export-DbaBinaryFile -Path C:\temp

Allows you to pick tables with columns to be exported by Export-DbaBinaryFile

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input.

Alias
Required False
Pipeline false
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported. For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Database

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-Table

Define a specific table you would like to query. You can specify up to three-part name like db.sch.tbl. If the object has special characters please wrap them in square brackets [ ]. Using dbo.First.Table will try to find table named 'Table' on schema 'First' and database 'dbo'. The correct way to find table named 'First.Table' on schema 'dbo' is by passing dbo.[First.Table] Any actual usage of the ] must be escaped by duplicating the ] character. The correct way to find a table Name] in schema Schema.Name is by passing [Schema.Name].[Name]]]

Alias
Required False
Pipeline false
Default Value
-Schema

Only return tables from the specified schema

Alias
Required False
Pipeline false
Default Value
-FileNameColumn

The column name that contains the filename. If not specified, we'll try out best to figure it out.

Alias
Required False
Pipeline false
Default Value
-BinaryColumn

The column name that contains the binary data. If not specified, we'll try out best to figure it out.

Alias
Required False
Pipeline false
Default Value
-Path

Specifies the directory where files will be exported.

Alias
Required False
Pipeline false
Default Value
-Query

Allows you to specify a custom query to use to return the data. If not specified, we'll try out best to figure it out. Example query: "SELECT [fn], [data] FROM tempdb.dbo.files"

Alias
Required False
Pipeline false
Default Value
-FilePath

The specific filename of the output file. If not specified, the filename will use the filename column to determine the filename.

Alias OutFile,FileName
Required False
Pipeline false
Default Value
-InputObject

Table objects to be piped in from Get-DbaDbTable or Get-DbaBinaryFileTable

Alias
Required False
Pipeline true (ByValue)
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command

Alias cf
Required False
Pipeline false
Default Value