Skip to content

Instantly share code, notes, and snippets.

@RichieBzzzt
Created January 16, 2018 15:34
Show Gist options
  • Save RichieBzzzt/4fcebb9fab03f31292d9c3835b7bf9cf to your computer and use it in GitHub Desktop.
Save RichieBzzzt/4fcebb9fab03f31292d9c3835b7bf9cf to your computer and use it in GitHub Desktop.
[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