Skip to content

Commit 36fc2f6

Browse files
committed
Add version check and comment updates
1 parent d3079d6 commit 36fc2f6

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

Registration/RegisterWithAzure.ps1

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.SYNOPSIS
77
88
This script can be used to register Azure Stack POC with Azure. To run this script, you must have a public Azure subscription of any type.
9-
There must also be an account that is an owner or contributor of the subscription. This account cannot be an MSA (i.e. cannot be live.com or hotmail.com) or 2FA account.
9+
There must also be an account that is an owner or contributor of the subscription.
1010
1111
.DESCRIPTION
1212
@@ -31,9 +31,9 @@ Name of your AAD Tenant which your Azure subscription is a part of. This paramet
3131
3232
Username for an owner/contributor of the azure subscription. This user must not be an MSA or 2FA account. This parameter is mandatory.
3333
34-
.PARAMETER azureCredentialPassword
34+
.PARAMETER azureAccountPassword
3535
36-
Password for the Azure subscription. You will be prompted to type in this password. This parameter is mandatory.
36+
Password for the Azure subscription. You will be prompted to type in this password if its not specified. Make sure JavaScript is enabled for the browser.
3737
3838
.PARAMETER azureEnvironment
3939
@@ -50,14 +50,15 @@ This script must be run from the Host machine of the POC.
5050
5151
5252
.NOTES
53-
Ensure that you have an Azure subscription
53+
Ensure that you have an Azure subscription and it is registered for Microsoft.AzureStack namespace in Azure.
54+
Namespace can be registered with the following command:
55+
Register-AzureRmResourceProvider -ProviderNamespace 'microsoft.azurestack'
5456
#>
5557

5658
[CmdletBinding()]
5759
param(
58-
59-
[Parameter(Mandatory=$true)]
60-
[SecureString] $azureCredentialPassword,
60+
[Parameter(Mandatory=$false)]
61+
[SecureString] $azureAccountPassword,
6162

6263
[Parameter(Mandatory=$true)]
6364
[String] $azureAccountId,
@@ -79,35 +80,44 @@ param(
7980

8081
[Parameter(Mandatory=$false)]
8182
[Switch] $reportUsage = $false
82-
)
83+
)
8384

8485
#requires -Module AzureRM.Profile
8586
#requires -Module AzureRM.Resources
8687
#requires -RunAsAdministrator
8788

88-
#
89-
# Wrapper script to test registration and activation
90-
# Uses refresh tokens and supports 2fa, MSA accounts
91-
#
92-
9389
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
9490
$VerbosePreference = [System.Management.Automation.ActionPreference]::Continue
9591

9692
Import-Module C:\CloudDeployment\ECEngine\EnterpriseCloudEngine.psd1 -Force
9793
Set-Location C:\CloudDeployment\Setup\Activation\Bridge
9894

9995
#
100-
# Pre-req: Obtain refresh token for Azure identity
96+
# Pre-req: Version check
10197
#
102-
Import-Module C:\CloudDeployment\Setup\Common\AzureADConfiguration.psm1 -ErrorAction Stop
10398

104-
$AzureCredential = New-Object System.Management.Automation.PSCredential($azureAccountId, $azureCredentialPassword)
99+
$versionInfo = [xml] (Get-Content -Path C:\CloudDeployment\Configuration\Version\version.xml)
100+
$minVersion = "1.0.170501.1"
101+
if($versionInfo.Version -lt $minVersion)
102+
{
103+
Write-Error -Message "Script only applicable for Azure Stack builds $minVersion or later"
104+
}
105+
else
106+
{
107+
Write-Verbose -Message "Running registration on build $($versionInfo.Version)" -Verbose
108+
}
109+
110+
#
111+
# Obtain refresh token for Azure identity
112+
#
105113

114+
Import-Module C:\CloudDeployment\Setup\Common\AzureADConfiguration.psm1 -ErrorAction Stop
106115
$AzureDirectoryTenantId = Get-TenantIdFromName -azureEnvironment $azureEnvironment -tenantName $azureDirectoryTenantName
107116

108-
if($AzureCredential)
117+
if($azureAccountPassword)
109118
{
110119
Write-Verbose "Using provided Azure Credentials to get refresh token"
120+
$AzureCredential = New-Object System.Management.Automation.PSCredential($azureAccountId, $azureAccountPassword)
111121
$tenantDetails = Get-AzureADTenantDetails -AzureEnvironment $azureEnvironment -AADDirectoryTenantName $azureDirectoryTenantName -AADAdminCredential $AzureCredential
112122
}
113123
else
@@ -138,11 +148,13 @@ Write-Verbose "New registration request completed"
138148
# Step 3: Register Azure Stack with Azure
139149
#
140150

151+
New-Item -ItemType Directory -Force -Path "C:\temp"
141152
$registrationRequestFile = "c:\temp\registration.json"
142153
$registrationOutputFile = "c:\temp\registrationOutput.json"
154+
143155
.\Register-AzureStack.ps1 -BillingModel PayAsYouUse -EnableSyndication -ReportUsage -SubscriptionId $azureSubscriptionId -AzureAdTenantId $AzureDirectoryTenantId `
144-
-RefreshToken $refreshToken -AzureAccountId $azureAccountId -AzureEnvironmentName $azureEnvironment -RegistrationRequestFile $registrationRequestFile `
145-
-RegistrationOutputFile $registrationOutputFile -Location "westcentralus" -Verbose
156+
-RefreshToken $refreshToken -AzureAccountId $azureAccountId -AzureEnvironmentName $azureEnvironment -RegistrationRequestFile $registrationRequestFile `
157+
-RegistrationOutputFile $registrationOutputFile -Location "westcentralus" -Verbose
146158
Write-Verbose "Register Azure Stack with Azure completed"
147159

148160
#

0 commit comments

Comments
 (0)