Skip to content

Commit ae5f304

Browse files
authored
Create RegisterWithAzure.ps1
This is a wrapper script for helping customers to walk through the steps of registering their Azure Stack with their Azure subscription.
1 parent 1cda83d commit ae5f304

1 file changed

Lines changed: 156 additions & 0 deletions

File tree

Registration/RegisterWithAzure.ps1

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# See LICENSE.txt in the project root for license information.
3+
4+
<#
5+
6+
.SYNOPSIS
7+
8+
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+
The owner of the subscription cannot be an MSA or 2FA account.
10+
11+
.DESCRIPTION
12+
13+
RegisterToAzure runs local scripts to connect your Azure Stack to Azure. After connecting with Azure, you can test marketplace syndication.
14+
15+
The script will follow four steps:
16+
Configure local identity: configures local Azure Stack so that it can call to Azure via your Azure subscription
17+
Get registration request: get local environment information to create a registration for this azure stack in azure
18+
Register with Azure: uses Azure powershell to create an "Azure Stack Registration" resource on your Azure subscription
19+
Activate Azure Stack: final step in connecting Azure Stack to be able to call out to Azure
20+
21+
.PARAMETER azureSubscriptionId
22+
23+
Azure subscription ID that you want to register your Azure Stack with. This parameter is mandatory.
24+
25+
.PARAMETER azureDirectory
26+
27+
Name of your AAD Tenant which your Azure subscription is a part of. This parameter is mandatory.
28+
29+
.PARAMETER azureSubscriptionOwner
30+
31+
Username for the owner of the azure subscription. This user must not be an MSA or 2FA account. This parameter is mandatory.
32+
33+
.PARAMETER azureSubscriptionPassword
34+
35+
Password for the Azure subscription. You will be prompted to type in this password. This parameter is mandatory.
36+
37+
.PARAMETER marketplaceSyndication
38+
39+
Flag (ON/OFF) whether to enable downloading items from the Azure marketplace on this environment. Defaults to "ON".
40+
41+
.PARAMETER reportUsage
42+
43+
Flag (ON/OFF) whether to enable pushing usage data to Azure on this environment. Defaults to "ON".
44+
45+
46+
.EXAMPLE
47+
48+
This script must be run from the Host machine of the POC.
49+
.\RegisterWithAzure.ps1 -azureSubscriptionId "5e0ae55d-0b7a-47a3-afbc-8b372650abd3" -azureDirectory "contoso.onmicrosoft.com" -azureSubscriptionOwner "serviceadmin@contoso.onmicrosoft.com"
50+
51+
52+
.NOTES
53+
Ensure that you have an Azure subscription
54+
#>
55+
56+
57+
[CmdletBinding()]
58+
Param (
59+
[Parameter(Mandatory = $true)]
60+
[string]$azureDirectory,
61+
62+
[Parameter(Mandatory = $true)]
63+
[String]$azureSubscriptionId,
64+
65+
[Parameter(Mandatory = $true)]
66+
[String]$azureSubscriptionOwner,
67+
68+
[Parameter(Mandatory = $true)]
69+
[securestring]$azureSubscriptionPassword,
70+
71+
[Parameter(Mandatory=$false)]
72+
[ValidateSet('On', 'Off')]
73+
[string] $marketplaceSyndication = 'On',
74+
75+
[Parameter(Mandatory=$false)]
76+
[ValidateSet('On', 'Off')]
77+
[string] $reportUsage = 'On'
78+
)
79+
80+
#requires -Module AzureRM.Profile
81+
#requires -Module AzureRM.Resources
82+
#requires -RunAsAdministrator
83+
84+
Import-Module C:\CloudDeployment\ECEngine\EnterpriseCloudEngine.psm1 -Force
85+
cd C:\CloudDeployment\Setup\Activation\Bridge
86+
87+
#
88+
# Step 1: Configure Bridge identity
89+
#
90+
91+
$azureCreds = New-Object System.Management.Automation.PSCredential($azureSubscriptionOwner, $azureSubscriptionPassword)
92+
.\Configure-BridgeIdentity.ps1 -AzureCredential $azureCreds -AzureDirectoryTenantId $azureDirectory -AzureEnvironment AzureCloud -Verbose
93+
Write-Host "STEP 1: Configure local identity completed"
94+
95+
#
96+
# Step 2: Create new registration request
97+
#
98+
99+
$bridgeAppConfigFile = "\\SU1FileServer\SU1_Infrastructure_1\ASResourceProvider\Config\ConnectionAzureArm.IdentityApplication.Configuration.json"
100+
$registrationOutputFile = "c:\temp\registration.json"
101+
.\New-RegistrationRequest.ps1 -BridgeAppConfigFile $bridgeAppConfigFile -RegistrationRequestOutputFile $registrationOutputFile -Verbose
102+
Read-Host "STEP 2: Registration request completed. Re-enter your Azure subscription credentials in the next step. Press Enter to continue."
103+
104+
#
105+
# Step 3: Register Azure Stack with Azure
106+
#
107+
108+
$registrationRequestFile = "c:\temp\registration.json"
109+
$registrationOutputFile = "c:\temp\registrationOutput.json"
110+
111+
Login-AzureRmAccount -EnvironmentName AzureCloud
112+
Select-AzureRmSubscription -SubscriptionId $azureSubscriptionId
113+
114+
# 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')
118+
{
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')
125+
{
126+
Start-Sleep 10
127+
128+
}
129+
}
130+
131+
.\Register-AzureStack.ps1 -BillingModel Consumption -Syndication $marketplaceSyndication -ReportUsage $reportUsage -SubscriptionId $azureSubscriptionId -AzureAdTenantId $azureDirectory `
132+
-AzureCredential $azureCreds -AzureEnvironmentName AzureCloud -RegistrationRequestFile $registrationRequestFile -RegistrationOutputFile $registrationOutputFile -Location "westcentralus" -Verbose
133+
Read-Host "STEP 3: Register Azure Stack with Azure completed. Press Enter to continue."
134+
135+
#
136+
# Step 4: Activate Azure Stack
137+
#
138+
139+
# temporary step to adjust registration output to expected format
140+
$reg = Get-Content $registrationOutputFile | ConvertFrom-Json
141+
$newProps = @{
142+
ObjectId = $reg.properties.ObjectId
143+
ProvisioningState = $reg.properties.provisioningState
144+
syndication = $marketplaceSyndication
145+
usagebridge = $reportUsage
146+
}
147+
$reg.properties = $newProps
148+
$reg | ConvertTo-Json -Depth 4 | Out-File -FilePath $registrationOutputFile
149+
150+
$regResponse = Get-Content -path "C:\Temp\registrationOutput.json"
151+
$bytes = [System.Text.Encoding]::Unicode.GetBytes($regResponse)
152+
$activationCode = [Convert]::ToBase64String($bytes)
153+
154+
.\Activate-Bridge.ps1 -activationCode $activationCode -Verbose
155+
Write-Host "STEP 4: Activate Azure Stack completed"
156+
Write-Host "Registration complete. You may now access Marketplace Management in the Admin UI"

0 commit comments

Comments
 (0)