Skip to content

Commit

Permalink
Add new login support for Azure SQL Dbs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhunt committed Feb 19, 2019
1 parent b655405 commit e6851bb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion functions/New-DbaLogin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,12 @@ function New-DbaLogin {
try {
if ($loginType -eq 'AsymmetricKey') { $sql = "CREATE LOGIN [$loginName] FROM ASYMMETRIC KEY [$currentAsymmetricKey]" }
elseif ($loginType -eq 'Certificate') { $sql = "CREATE LOGIN [$loginName] FROM CERTIFICATE [$currentCertificate]" }
elseif ($loginType -eq "SqlLogin") { $sql = "CREATE LOGIN [$loginName] WITH PASSWORD = $currentHashedPassword HASHED" + $withParams }
elseif ($loginType -eq 'SqlLogin' -and $server.DatabaseEngineType -eq 'SqlAzureDatabase') {
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword) # Azure SQL doesn't support HASHED so we have to dump out the plain text password :(
$unsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$sql = "CREATE LOGIN [$loginName] WITH PASSWORD = '$unsecurePassword'"
}
elseif ($loginType -eq 'SqlLogin' ) { $sql = "CREATE LOGIN [$loginName] WITH PASSWORD = $currentHashedPassword HASHED" + $withParams }
else { $sql = "CREATE LOGIN [$loginName] FROM WINDOWS" + $withParams }

$null = $server.Query($sql)
Expand Down

0 comments on commit e6851bb

Please sign in to comment.