functions/Publish-DosDacPac.ps1
<#
.SYNOPSIS Publishes the traget DOS dac file to the specified database with the specified options .DESCRIPTION Uses Microsoft.SqlServer.Dac.DacServices to install DAC file to specified server. .PARAMETER DacPacFilePath File path to dacpac file to publish to server .PARAMETER SqlServerConnectionString Sql server connection string .PARAMETER TargetDb Target database to publish dac pac to. .PARAMETER PublishOptionsFilePath Path to publish options file. Null is valid and will publish with default options - see documentation here: https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dac.dacdeployoptions(v=sql.120).aspx .EXAMPLE Publish-DosDacPac -DacPacFilePath ".\test.dac" -TargetSqlInstance "localhost" -TargetDb "EDWAdmin" -PublishOptionsFilePath ".\test.publish.xml" #> function Publish-DosDacPac { [CmdletBinding()] param( [Parameter(Mandatory=$true)][string] $DacPacFilePath, [Parameter(Mandatory=$true)][string] $TargetSqlInstance, [Parameter(Mandatory=$true)][string] $TargetDb, [Parameter(Mandatory=$true)][string] $PublishOptionsFilePath ) try{ Publish-DbaDacpac -SqlInstance $TargetSqlInstance -Database $TargetDb -Path $DacPacFilePath -PublishXml $PublishOptionsFilePath -EnableException } catch{ Write-Error "Unable to deploy $DacPacFilePath to $TargetDb on $TargetSqlInstance. Exception: $_" } } |