Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Import-DbaBinaryFile on GitHub.
Want to see the Bill Of Health for this command? Check out Import-DbaBinaryFile.
Imports binary files into SQL Server
Imports binary files into 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.
Import-DbaBinaryFile
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Database] <String>]
[[-Table] <String>]
[[-Schema] <String>]
[[-Statement] <String>]
[[-FileNameColumn] <String>]
[[-BinaryColumn] <String>]
[-NoFileNameColumn]
[[-InputObject] <Table[]>]
[[-FilePath] <FileInfo[]>]
[[-Path] <FileInfo[]>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Get-ChildItem C:\photos | Import-DbaBinaryFile -SqlInstance sqlcs -Database employees -Table photos
Imports all photos from C:\photos into the photos table in the employees database on sqlcs. Automatically guesses the column names for the image and filename columns.
PS C:\> Import-DbaBinaryFile -SqlInstance sqlcs -Database tempdb -Table BunchOFiles -FilePath C:\azure\adalsql.msi
Imports the file adalsql.msi into the BunchOFiles table in the tempdb database on sqlcs. Automatically guesses the column names for the image and filename columns.
PS C:\> Import-DbaBinaryFile -SqlInstance sqlcs -Database tempdb -Table BunchOFiles -FilePath C:\azure\adalsql.msi -FileNameColumn fname -BinaryColumn data
Imports the file adalsql.msi into the BunchOFiles table in the tempdb database on sqlcs. Uses the fname and data columns for the filename and binary data.
The target SQL Server instance or instances. This can be a collection and receive pipeline input.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
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 |
Define a specific table you would like to upload to. 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 |
The specific schema to use. If not specified, the default schema will be used.
Alias | |
Required | False |
Pipeline | false |
Default Value |
To upload files, you basically have to use a statement line this:
INSERT INTO db.tbl ([FileNameColumn], [bBinaryColumn]) VALUES (@FileName, @FileContents)
We try our best to guess the column names, but if you need to specify the SQL statement, use this parameter. The only required parameter is @FileContents. If you want to use a filename column, you
must use @FileName.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The column name that will contain the filename. If not specified, we will try to guess based on the column name.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The column name that will contain the binary data. If not specified, we will try to guess based on the column name.
Alias | |
Required | False |
Pipeline | false |
Default Value |
If you don't have a filename column, use this switch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Table objects to be piped in from Get-DbaDbTable or Get-DbaBinaryFileTable
Alias | |
Required | False |
Pipeline | true (ByValue) |
Default Value |
Specifies the full file path of the output file. Accepts pipeline input from Get-ChildItem.
Alias | FullName |
Required | False |
Pipeline | true (ByPropertyName) |
Default Value |
A directory full of files to import.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
Shows what would happen if the command were to run. No actions are actually performed
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command
Alias | cf |
Required | False |
Pipeline | false |
Default Value |