Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[cmdletbinding()]
param (
[parameter(Mandatory=$true)][string]$DacpacPath,
[parameter(Mandatory=$true)][string]$InstanceName,
[parameter(Mandatory=$true)][string]$DatabaseName,
[parameter(Mandatory=$false)][string]$PublishProfile,
[parameter(Mandatory=$false)][string]$UserName,
[parameter(Mandatory=$false)][securestring]$Password,
[parameter(Mandatory=$false)][switch]$GenerateDeploymentScript
)
if (-not (get-module -Name dbatools -ListAvailable)) {
Write-Verbose "Installing dbatools from PSGallery"
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module dbatools
}
Import-Module dbatools
$PublishParams = @{
SqlInstance = $InstanceName
Path = (Resolve-Path $DacpacPath)
Database = $DatabaseName
PublishXml = (Resolve-Path $PublishProfile)
GenerateDeploymentScript = $GenerateDeploymentScript
}
if ($UserName) {
$PublishParams.Add("SqlCredential", (New-Object System.Management.Automation.PSCredential ($UserName, $Password)))
}
Publish-DbaDacpac @PublishParams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment