@@ -104,29 +104,37 @@ Read-Host "STEP 2: Registration request completed. Re-enter your Azure subscript
104104#
105105# Step 3: Register Azure Stack with Azure
106106#
107-
107+ New-Item - ItemType Directory - Force - Path " C:\temp "
108108$registrationRequestFile = " c:\temp\registration.json"
109109$registrationOutputFile = " c:\temp\registrationOutput.json"
110110
111111Login- AzureRmAccount - EnvironmentName AzureCloud
112112Select-AzureRmSubscription - SubscriptionId $azureSubscriptionId
113113
114114# Ensure subscription is registered to Microsoft.AzureStack namespace in Azure
115- $regState = $ (Get-AzureRmResourceProvider - ProviderNamespace ' microsoft.azurestack' )[0 ].RegistrationState
116- $regState
117- while ($regState -ne ' Registered' )
115+ Register-AzureRmResourceProvider - ProviderNamespace ' microsoft.azurestack'
116+ $result = $null
117+ $attempts = 0
118+ $maxAttempts = 20
119+ $delayInSecondsBetweenAttempts = 10
120+ do
118121{
119- $regState = $ (Get-AzureRmResourceProvider - ProviderNamespace ' microsoft.azurestack' )[0 ].RegistrationState
120- if ($regState -eq ' NotRegistered' -or $regState -eq ' UnRegistered' )
121- {
122- Register-AzureRmResourceProvider - ProviderNamespace ' microsoft.azurestack'
123- }
124- elseif ($regState -eq ' Registering' )
122+ $attempts ++
123+ Write-Verbose " [CHECK] Checking for resource provider registration... (attempt $attempts of $maxAttempts )"
124+ $result = $ (Get-AzureRmResourceProvider - ProviderNamespace ' microsoft.azurestack' )[0 ].RegistrationState -EQ ' Registered'
125+ $result
126+ if ((-not $result ) -and ($attempts -lt $maxAttempts ))
125127 {
126- Start-Sleep 10
127-
128+ Write-Verbose " [DELAY] Attempt $attempts failed to see provider registration, delaying for $delayInSecondsBetweenAttempts seconds before retry "
129+ Start-Sleep - Seconds $delayInSecondsBetweenAttempts
128130 }
129131}
132+ while ((-not $result ) -and ($attempts -lt $maxAttempts ))
133+
134+ if (-not $result )
135+ {
136+ throw New-Object System.InvalidOperationException(" Azure Bridge Resource Provider was registered but did not become routable within the alloted time" )
137+ }
130138
131139.\Register-AzureStack.ps1 - BillingModel Consumption - Syndication $marketplaceSyndication - ReportUsage $reportUsage - SubscriptionId $azureSubscriptionId - AzureAdTenantId $azureDirectory `
132140 - AzureCredential $azureCreds - AzureEnvironmentName AzureCloud - RegistrationRequestFile $registrationRequestFile - RegistrationOutputFile $registrationOutputFile - Location " westcentralus" - Verbose
@@ -147,7 +155,7 @@ usagebridge = $reportUsage
147155$reg.properties = $newProps
148156$reg | ConvertTo-Json - Depth 4 | Out-File - FilePath $registrationOutputFile
149157
150- $regResponse = Get-Content - path " C:\Temp\registrationOutput.json "
158+ $regResponse = Get-Content - path $registrationOutputFile
151159$bytes = [System.Text.Encoding ]::Unicode.GetBytes($regResponse )
152160$activationCode = [Convert ]::ToBase64String($bytes )
153161
0 commit comments