<# .SYNOPSIS Export Azure Managed SQL Database to bacpac file .DESCRIPTION Uses sqlpackage.exe to export a database. #> cd 'C:\Program Files\Microsoft SQL Server\150\DAC\bin' $DBACredential = Get-Credential -UserName pgadmin -Message 'Backup Credential: Total SQL DBA (Azure) in Lastpass' $Database='' if(-not $Database) { Write-Error "Please configure database" } $Server='tcp:tot-2020-sql-acceptance.03ddfc49f186.database.windows.net,1433' #sqlpackage.exe /Action:Export /ssn:tcp:MyOwnServer.database.windows.net,1433 /sdn:AdventureWorks /su:AdminUser /sp:AdminPassword1 /tf:C:\Temp\AW.bacpac /p:Storage=File ./sqlpackage.exe /Action:Export /ssn:$server /sdn:$database /su:pgadmin /sp:$($DBACredential.GetNetworkCredential().Password) /tf:F:\export\$($Database).bacpac /p:Storage=File