From e6851bb604d15e8bdc98d75ae59d4e66f290e698 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Tue, 19 Feb 2019 15:40:21 -0500 Subject: [PATCH 1/2] Add new login support for Azure SQL Dbs Fixes #5100 --- functions/New-DbaLogin.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions/New-DbaLogin.ps1 b/functions/New-DbaLogin.ps1 index e24be030b0..eb0c8d5a92 100644 --- a/functions/New-DbaLogin.ps1 +++ b/functions/New-DbaLogin.ps1 @@ -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) From 4b1625b034af355b353937a9b942a1ddd8c674cb Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Tue, 19 Feb 2019 16:05:47 -0500 Subject: [PATCH 2/2] Correct formatting --- functions/New-DbaLogin.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/New-DbaLogin.ps1 b/functions/New-DbaLogin.ps1 index eb0c8d5a92..89307605c6 100644 --- a/functions/New-DbaLogin.ps1 +++ b/functions/New-DbaLogin.ps1 @@ -423,8 +423,7 @@ function New-DbaLogin { $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 } + } 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)