Skip to content

Commit ad6b4ef

Browse files
authored
Merge pull request #528 from Azure/user/rakku/remove-azsactivationresource-fix
Remove-AzsActivationResource update
2 parents dd6acf5 + d7d12ba commit ad6b4ef

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed

Registration/RegisterWithAzure.psm1

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -970,16 +970,11 @@ param(
970970
<#
971971
.SYNOPSIS
972972
973-
Removes the activation resource created during New-AzsActivationResource
973+
De-activates Azure Stack in Disconnected Environments
974974
975975
.DESCRIPTION
976976
977-
Prompts the user to log in to the Azure Stack Administrator account, finds and removes the activation resource created
978-
during New-AzsActivationResource. This will remove any downloaded marketplace products.
979-
980-
.PARAMETER AzureStackAdminSubscriptionId
981-
982-
The subscription id of the Azure Stack administrator. This user must have access to the 'marketplace management' blade.
977+
Takes Azure Stack PrivilegedEndpoint and PrivilegedEndpoint credential as input, and deactivates the activation properties created by New-AzsActivationResource
983978
984979
#>
985980
Function Remove-AzsActivationResource{
@@ -989,13 +984,7 @@ Function Remove-AzsActivationResource{
989984
[PSCredential] $PrivilegedEndpointCredential,
990985

991986
[Parameter(Mandatory = $true)]
992-
[String] $PrivilegedEndpoint,
993-
994-
[Parameter(Mandatory = $false)]
995-
[String] $AzureStackAdminSubscriptionId,
996-
997-
[Parameter(Mandatory = $false)]
998-
[String] $AzureEnvironmentName = "AzureStack"
987+
[String] $PrivilegedEndpoint
999988
)
1000989

1001990
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
@@ -1008,27 +997,9 @@ Function Remove-AzsActivationResource{
1008997
try
1009998
{
1010999
$session = Initialize-PrivilegedEndpointSession -PrivilegedEndpoint $PrivilegedEndpoint -PrivilegedEndpointCredential $PrivilegedEndpointCredential -Verbose
1011-
1012-
$AzureStackStampInfo = Invoke-Command -Session $session -ScriptBlock { Get-AzureStackStampInformation }
1013-
Log-Output "Logging in to AzureStack administrator account. TenantId: $($AzureStackStampInfo.AADTenantID) Environment: 'AzureStack'"
1014-
Login-AzureRmAccount -TenantId $AzureStackStampInfo.AADTenantID -Environment $AzureEnvironmentName
1015-
$azureStackContext = Get-AzureRmContext
1016-
1017-
$azureStackContextDetails = @{
1018-
Account = $azureStackContext.Account
1019-
Environment = $azureStackContext.Environment
1020-
Subscription = $azureStackContext.Subscription
1021-
Tenant = $azureStackContext.Tenant
1022-
}
1023-
1024-
Log-Output "Successfully logged into Azure Stack account: $(ConvertTo-Json $azureStackContextDetails)"
1025-
if (-not $AzureStackAdminSubscriptionId)
1026-
{
1027-
$AzureStackAdminSubscriptionId = $azureStackContext.Subscription.Id
1028-
}
1029-
$activationResource = Get-AzureRmResource -ResourceId "/subscriptions/$AzureStackAdminSubscriptionId/resourceGroups/azurestack-activation/providers/Microsoft.AzureBridge.Admin/activations/default"
1030-
Log-Output "Activation resource found: $(ConvertTo-Json $activationResource)"
1031-
Remove-AzureRmResource -ResourceId $activationResource.ResourceId -Force
1000+
Log-Output "Successfully initialized session with endpoint: $PrivilegedEndpoint"
1001+
Log-Output "De-Activating Azure Stack (this may take up to 10 minutes to complete)."
1002+
Invoke-Command -Session $session -ScriptBlock { Remove-AzureStackActivation }
10321003
}
10331004
catch
10341005
{
@@ -1042,7 +1013,7 @@ Function Remove-AzsActivationResource{
10421013
}
10431014
}
10441015

1045-
Log-Output "Activation resource has been removed from Azure Stack."
1016+
Log-Output "Successfully de-activated Azure Stack"
10461017
Log-Output "*********************** End log: $($PSCmdlet.MyInvocation.MyCommand.Name) ***********************`r`n`r`n"
10471018
}
10481019

0 commit comments

Comments
 (0)