Skip to content

Commit e396cf0

Browse files
authored
Merge pull request #408 from ChrisKXu/icm62397587
Add Start-ResourceSynchronization.ps1 to Support scripts
2 parents f616e3d + 26608b7 commit e396cf0

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<#
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
.SYNOPSIS
4+
This script initiates a resource synchronization job in the backend, fixing the documented known issue where the Storage Account Overview does not load within Azure Stack portals (both Admin and User portals) for Storage accounts created with "apiVersion": "2015-06-15".
5+
6+
.DESCRIPTION
7+
Created to be run on the HLH, DVM, ASDK HOST or Jumpbox from an administrative powershell session.
8+
Start-ResourceSynchronization.ps1 must be run after the user has logged in as the Service Admin to the Default Provider Subscription within their Azure Stack subscription.
9+
10+
Applies to: Azure Stack Integraded System and ASDK
11+
Relevant build(s): 1802
12+
13+
It can be run without any parameters - if done so, it will initiate the resource synchronization on the Default Provider Subscription as well as any available User Subscriptions.
14+
NOTE: A warning will be thrown (-WarningAction Inquire) if more than 10 subscriptions exist, as there could be a performance impact during the execution of the resource synchronization agianst all the user subscriptions at once.
15+
Alternatively, the script can be run one subscription at a time, leveraging the optional SubscriptionId parameter.
16+
17+
.PARAMETER SubscriptionId
18+
OPTIONAL [Guid] parameter specifying a single subscription to run the resource synchronization against.
19+
Use this option for targeted subscription resource synchronization.
20+
21+
.EXAMPLE
22+
.\Start-ResourceSynchronization.ps1
23+
24+
.EXAMPLE
25+
.\Start-ResourceSynchronization.ps1 -SubscriptionId 9b291bc8-fdef-4f88-bf81-8a0a53d4c2c5
26+
27+
.NOTES
28+
The following are the prerequisite steps to be completed before running Start-ResourceSynchronization.ps1
29+
30+
1. Install Azure and Azure Stack PowerShell (leverage current documented guidance for supported versions)
31+
2. Add an Azure Stack Environment (leverave current documented guidance for adding an adminmanagement environment)
32+
Example: Add-AzureRmEnvironment -Name AzureStackAdmin -ARMEndpoint "https://adminmanagement.local.azurestack.external"
33+
3. Login as the Service Admin to the Azure Stack environment (for Azure Stack environments deployed with AAD, identify the TenantID)
34+
Example: Login-AzureRmAccount -Environment AzureStackAdmin -TenantId 9b291bc8-fdef-4f88-bf81-8a0a53d4c2c5
35+
36+
Within the same PS session, Start-ResourceSynchronization.ps1 can now be run
37+
38+
.LINK
39+
https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-powershell-install
40+
41+
.LINK
42+
https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-powershell-configure-admin
43+
44+
.LINK
45+
https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-update-1802
46+
47+
.LINK
48+
https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-asdk-release-notes#build-201803021
49+
#>
50+
51+
[CmdletBinding()]
52+
param
53+
(
54+
[Guid] $SubscriptionId
55+
)
56+
57+
function IsNotNullOrEmptyString([Object]$Obj) { return ($Obj -ne $null) -and ($Obj.ToString() -ne "") }
58+
59+
Import-Module AzureRM.Profile
60+
Import-Module AzureRM.AzureStackAdmin
61+
62+
$adminSubscription = (Get-AzureRmSubscription -SubscriptionName "Default Provider Subscription" -ErrorAction Stop).SubscriptionId
63+
64+
$subscriptions = @($adminSubscription)
65+
66+
if (IsNotNullOrEmptyString $SubscriptionId)
67+
{
68+
$subscriptions += $SubscriptionId
69+
}
70+
else
71+
{
72+
$userSubscriptions = (Get-AzsUserSubscription | Select-Object -ExpandProperty SubscriptionId)
73+
$subscriptions += $userSubscriptions
74+
}
75+
76+
$subscriptions = $subscriptions | Select-Object -Unique
77+
78+
if ($subscriptions.Count -gt 10)
79+
{
80+
Write-Warning "You have more than 10 subscriptions. Synchronizing all these subscriptions might cause performance degradation during the resynchronization period." -WarningAction Inquire
81+
}
82+
83+
Write-Host "Starting resource synchronization job"
84+
85+
$subscriptions | ForEach-Object {
86+
$resourceId = "/subscriptions/$adminSubscription/providers/Microsoft.Resources.Admin/subscriptions/$_/providers/Microsoft.Storage"
87+
88+
$params = @{
89+
Action = "SynchronizeResources"
90+
ApiVersion = "2015-01-01"
91+
ResourceId = $resourceId
92+
}
93+
Invoke-AzureRmResourceAction @params -Force
94+
95+
Start-Sleep -Seconds 20
96+
}
97+
98+
Write-Host "Resource synchronization job started."

0 commit comments

Comments
 (0)