Created
January 16, 2018 15:34
-
-
Save RichieBzzzt/4fcebb9fab03f31292d9c3835b7bf9cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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