Skip to content

Commit

Permalink
Merge pull request #5102 from cdhunt/development
Browse files Browse the repository at this point in the history
Add new login support for Azure SQL Dbs
  • Loading branch information
potatoqualitee authored Feb 19, 2019
2 parents b655405 + 4b1625b commit df87c22
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion functions/New-DbaLogin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ 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 df87c22

Please sign in to comment.