Skip to content

Commit 496f7ca

Browse files
author
BradleyBartlett
committed
Rename param JeaComputerName to PrivilegedEndpoint; specify refresh token
1 parent 9e2617b commit 496f7ca

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

Registration/RegisterWithAzure.psm1

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The subscription Id that will be used for marketplace syndication and usage. The
5353
5454
The Azure tenant directory where you would like your registration resource in Azure to be created.
5555
56-
.PARAMETER JeaComputerName
56+
.PARAMETER PrivilegedEndpoint
5757
5858
Just-Enough-Access Computer Name, also known as Emergency Console VM.(Example: AzS-ERCS01 for the ASDK)
5959
@@ -94,25 +94,25 @@ Used when the billing model is set to capacity. If this is the case you will nee
9494
9595
This example registers your AzureStack environment with Azure, enables syndication, and enables usage reporting to Azure.
9696
97-
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -JeaComputername "Azs-ERCS01"
97+
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -PrivilegedEndpoint "Azs-ERCS01"
9898
9999
.EXAMPLE
100100
101101
This example registers your AzureStack environment with Azure, enables syndication, and disables usage reporting to Azure.
102102
103-
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -JeaComputername "Azs-ERCS01" -BillingMode 'Capacity' -UsageReportingEnabled:$false -AgreementNumber $MyAgreementNumber
103+
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -PrivilegedEndpoint "Azs-ERCS01" -BillingMode 'Capacity' -UsageReportingEnabled:$false -AgreementNumber $MyAgreementNumber
104104
105105
.EXAMPLE
106106
107107
This example registers your AzureStack environment with Azure, enables syndication and usage and gives a specific name to the resource group and registration resource.
108108
109-
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -JeaComputername "Azs-ERCS02" -ResourceGroupName "ContosoStackRegistrations" -RegistrationName "ContosoRegistration"
109+
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -PrivilegedEndpoint "Azs-ERCS02" -ResourceGroupName "ContosoStackRegistrations" -RegistrationName "ContosoRegistration"
110110
111111
.EXAMPLE
112112
113113
This example disables syndication and disables usage reporting to Azure. Note that usage will still be collected, just not sent to Azure.
114114
115-
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -JeaComputername "Azs-ERCS01" -BillingModel Development -MarketplaceSyndicationEnabled:$false -UsageReportingEnabled:$false
115+
Add-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $SubscriptionId -AzureDirectoryTenantName "contoso.onmicrosoft.com" -PrivilegedEndpoint "Azs-ERCS01" -BillingModel Development -MarketplaceSyndicationEnabled:$false -UsageReportingEnabled:$false
116116
117117
.NOTES
118118
@@ -135,7 +135,7 @@ Function Add-AzsRegistration{
135135
[String] $AzureDirectoryTenantName,
136136

137137
[Parameter(Mandatory = $true)]
138-
[String] $JeaComputerName,
138+
[String] $PrivilegedEndpoint,
139139

140140
[Parameter(Mandatory = $false)]
141141
[String] $ResourceGroupName = 'azurestack',
@@ -208,7 +208,7 @@ The subscription Id that was previously used to register this Azure Stack enviro
208208
209209
The Azure tenant directory previously used to register this Azure Stack environment with Azure.
210210
211-
.PARAMETER JeaComputerName
211+
.PARAMETER PrivilegedEndpoint
212212
213213
Just-Enough-Access Computer Name, also known as Emergency Console VM.(Example: AzS-ERCS01 for the ASDK).
214214
@@ -228,7 +228,7 @@ The name of the Azure Environment where registration resources have been created
228228
229229
This example removes a registration resource in Azure that was created from a prior successful run of Add-AzsRegistration and uses defaults for RegistrationName and ResourceGroupName.
230230
231-
Remove-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $AzureSubscriptionId -AzureDirectoryTenantName 'contoso.onmicrosoft.com' -JeaComputerName $JeaComputerName
231+
Remove-AzsRegistration -CloudAdminCredential $CloudAdminCredential -AzureSubscriptionId $AzureSubscriptionId -AzureDirectoryTenantName 'contoso.onmicrosoft.com' -PrivilegedEndpoint $PrivilegedEndpoint
232232
233233
.NOTES
234234
@@ -250,7 +250,7 @@ function Remove-AzsRegistration{
250250
[String] $AzureDirectoryTenantName,
251251

252252
[Parameter(Mandatory = $true)]
253-
[String] $JeaComputerName,
253+
[String] $PrivilegedEndpoint,
254254

255255
[Parameter(Mandatory = $false)]
256256
[String] $ResourceGroupName = 'azurestack',
@@ -366,7 +366,7 @@ The Azure tenant directory previously used to register this Azure Stack environm
366366
367367
The subscription Id you would like to change your registration to.
368368
369-
.PARAMETER JeaComputerName
369+
.PARAMETER PrivilegedEndpoint
370370
371371
Just-Enough-Access Computer Name, also known as Emergency Console VM.(Example: AzS-ERCS01 for the ASDK).
372372
@@ -389,7 +389,7 @@ The name of the Azure Environment where registration resources have been created
389389
.EXAMPLE
390390
391391
Set-AzsRegistrationSubscription -CloudAdminCredential $CloudAdminCredential -CurrentAzureSubscriptionId $CurrentSubscriptionId -AzureDirectoryTenantName 'contoso.onmicrosoft.com' -NewAzureSubscriptionId $NewAzureSubscriptionId `
392-
-JeaComputerName <Prefix>-ERCS01 -NewAzureDirectoryTenantname 'microsoft.onmicrosoft.com'
392+
-PrivilegedEndpoint <Prefix>-ERCS01 -NewAzureDirectoryTenantname 'microsoft.onmicrosoft.com'
393393
394394
.NOTES
395395
@@ -416,7 +416,7 @@ function Set-AzsRegistrationSubscription{
416416
[String] $NewAzureSubscriptionId,
417417

418418
[Parameter(Mandatory = $true)]
419-
[String] $JeaComputerName,
419+
[String] $PrivilegedEndpoint,
420420

421421
[Parameter(Mandatory = $true)]
422422
[String] $NewAzureDirectoryTenantName,
@@ -534,7 +534,7 @@ function RegistrationWorker{
534534
[String] $AzureDirectoryTenantName,
535535

536536
[Parameter(Mandatory = $true)]
537-
[String] $JeaComputerName,
537+
[String] $PrivilegedEndpoint,
538538

539539
[Parameter(Mandatory = $false)]
540540
[String] $ResourceGroupName = 'azurestack',
@@ -572,7 +572,7 @@ function RegistrationWorker{
572572

573573
Log-Output "Logging in to Azure."
574574
$connection = Connect-AzureAccount -SubscriptionId $AzureSubscriptionId -AzureEnvironment $AzureEnvironmentName -AzureDirectoryTenantName $AzureDirectoryTenantName -Verbose
575-
$session = Initialize-PrivilegedJeaSession -JeaComputerName $JeaComputerName -CloudAdminCredential $CloudAdminCredential -Verbose
575+
$session = Initialize-PrivilegedJeaSession -PrivilegedEndpoint $PrivilegedEndpoint -CloudAdminCredential $CloudAdminCredential -Verbose
576576
$stampInfo = Confirm-StampVersion -PSSession $session
577577
$tenantId = $connection.TenantId
578578
$refreshToken = $connection.Token.RefreshToken
@@ -696,7 +696,7 @@ function RegistrationWorker{
696696

697697
Log-Output "Activating Azure Stack (this may take up to 10 minutes to complete)."
698698
$activation = Invoke-Command -Session $session -ScriptBlock { New-AzureStackActivation -ActivationKey $using:actionResponse.ActivationKey }
699-
Log-Output "Azure Stack registration and activation completed successfully. Logs can be found at: $Global:AzureRegistrationLog and \\$JeaComputerName\c$\maslogs"
699+
Log-Output "Azure Stack registration and activation completed successfully. Logs can be found at: $Global:AzureRegistrationLog and \\$PrivilegedEndpoint\c$\maslogs"
700700
}
701701
finally
702702
{
@@ -855,12 +855,20 @@ function Connect-AzureAccount{
855855
}
856856
else
857857
{
858-
$token = $tokens[0]
858+
$token = $tokens |
859+
Where Resource -EQ $environment.ActiveDirectoryServiceEndpointResourceId |
860+
Where { $_.TenantId -eq $subscription.TenantId } |
861+
Where { $_.ExpiresOn -gt [datetime]::UtcNow } |
862+
Select -First 1
859863
}
860864
}
861865
else
862866
{
863-
$token = $tokens[0]
867+
$token = $tokens |
868+
Where Resource -EQ $environment.ActiveDirectoryServiceEndpointResourceId |
869+
Where { $_.TenantId -eq $subscription.TenantId } |
870+
Where { $_.ExpiresOn -gt [datetime]::UtcNow } |
871+
Select -First 1
864872
}
865873
}
866874
else
@@ -902,14 +910,14 @@ function Connect-AzureAccount{
902910
903911
.SYNOPSIS
904912
905-
Creates a powershell session with the JeaComputer for registration actions
913+
Creates a powershell session with the PrivilegedEndpoint for registration actions
906914
907915
#>
908916
function Initialize-PrivilegedJeaSession{
909917
[CmdletBinding()]
910918
Param(
911919
[Parameter(Mandatory=$true)]
912-
[String] $JeaComputerName,
920+
[String] $PrivilegedEndpoint,
913921

914922
[Parameter(Mandatory=$true)]
915923
[PSCredential] $CloudAdminCredential
@@ -921,14 +929,14 @@ Param(
921929
{
922930
try
923931
{
924-
Log-Output "Initializing privileged JEA session with $JeaComputerName. Attempt $currentAttempt of $maxAttempts"
925-
$session = New-PSSession -ComputerName $JeaComputerName -ConfigurationName PrivilegedEndpoint -Credential $CloudAdminCredential
926-
Log-Output "Connection to $JeaComputerName successful"
932+
Log-Output "Initializing privileged JEA session with $PrivilegedEndpoint. Attempt $currentAttempt of $maxAttempts"
933+
$session = New-PSSession -ComputerName $PrivilegedEndpoint -ConfigurationName PrivilegedEndpoint -Credential $CloudAdminCredential
934+
Log-Output "Connection to $PrivilegedEndpoint successful"
927935
return $session
928936
}
929937
catch
930938
{
931-
Log-Warning "Creation of session with $JeaComputerName failed:`r`n$($_.Exception.Message)"
939+
Log-Warning "Creation of session with $PrivilegedEndpoint failed:`r`n$($_.Exception.Message)"
932940
Log-Output "Waiting $sleepSeconds seconds and trying again..."
933941
$currentAttempt++
934942
Start-Sleep -Seconds $sleepSeconds
@@ -944,7 +952,7 @@ Param(
944952
945953
.SYNOPSIS
946954
947-
Uses the current session with the JeaComputer to determine the version of Azure Stack that has been deployed
955+
Uses the current session with the PrivilegedEndpoint to determine the version of Azure Stack that has been deployed
948956
949957
#>
950958
function Confirm-StampVersion{
@@ -1120,7 +1128,7 @@ function Log-Throw
11201128
"***************************************************************`r`n" | Out-File $Global:AzureRegistrationLog -Append
11211129
Log-Output "*********************** Ending registration action during $CallingFunction ***********************`r`n`r`n"
11221130

1123-
throw "Logs can be found at: $Global:AzureRegistrationLog and \\$JeaComputerName\c$\maslogs `r`n$Message"
1131+
throw "Logs can be found at: $Global:AzureRegistrationLog and \\$PrivilegedEndpoint\c$\maslogs `r`n$Message"
11241132
}
11251133

11261134
Export-ModuleMember Add-AzsRegistration

0 commit comments

Comments
 (0)