Skip to content

Commit 691412c

Browse files
Merge pull request #223 from Azure-Samples/users/evan/fixAADSetupScript
Fix AAD Setup Script Issue
2 parents a25d849 + d9bf864 commit 691412c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

blockchain-workbench/scripts/aad-setup/workbenchAADSetup.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,26 @@ function Log-Error {
109109
if (Get-Module -ListAvailable -Name "AzureAD.Standard.Preview") {
110110
Log-Debug "Importing module AzureAD.Standard.Preview"
111111
Import-Module "AzureAD.Standard.Preview"
112+
113+
# Issue: https://github.com/Azure-Samples/blockchain/issues/222
114+
# Azure cloud shell deliberately hided Connect-AzureAD cmdlet in a 2020 Feb update and used a wrapper with identical
115+
# name Connect-AzureAD. This change pollutes cmdlet names in this script. The following line fixes the issue:
116+
117+
# Create an alias for Connect-AzureAD cmdlet depending on the version of AAD module
118+
# so that the cmdlet could be used easier later
119+
Set-Alias -Name Connect-AzureADAlias -Value "AzureAD.Standard.Preview\Connect-AzureAD"
120+
112121
# For Windows PowerShell
113122
} elseif (Get-Module -ListAvailable -Name "AzureADPreview") {
114123
Log-Debug "Importing module AzureADPreview"
115124
Import-Module "AzureADPreview"
125+
Set-Alias -Name Connect-AzureADAlias -Value "AzureADPreview\Connect-AzureAD"
126+
116127
} elseif (Get-Module -ListAvailable -Name "AzureAD") {
117128
Log-Debug "Importing module AzureAD"
118129
Import-Module "AzureAD"
130+
Set-Alias -Name Connect-AzureADAlias -Value "AzureAD\Connect-AzureAD"
131+
119132
} else {
120133
Log-Error "This script is not compatible with your computer, Please use Azure CloudShell https://shell.azure.com/powershell" -Exit
121134
}
@@ -181,7 +194,7 @@ Do {
181194
try {
182195
if ($TenantName) {
183196
Log-Debug "Trying to login to $TenantName"
184-
$currentUser = Connect-AzureAD -TenantId $TenantName -ErrorAction SilentlyContinue
197+
$currentUser = Connect-AzureADAlias -TenantId $TenantName -ErrorAction SilentlyContinue
185198
} else {
186199
continue;
187200
}

0 commit comments

Comments
 (0)