-
Notifications
You must be signed in to change notification settings - Fork 16.2k
/
SideLoad-AzCreateUIDefinition.ps1
60 lines (44 loc) · 2.5 KB
/
SideLoad-AzCreateUIDefinition.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Requires -Version 3.0
#Requires -Module Az.Resources
#Requires -Module Az.Storage
#use this script to side-load a createUIDefinition.json file in the Azure portal
[cmdletbinding()]
param(
[string] $ArtifactsStagingDirectory = ".",
[string] $createUIDefFile='createUIDefinition.json',
[string] $storageContainerName='createuidef',
[string] $StorageResourceGroupLocation, # this must be specified only when the staging resource group needs to be created - first run or if the account has been deleted
[switch] $Gov
)
try {
$StorageAccountName = 'stage' + ((Get-AzContext).Subscription.Id).Replace('-', '').substring(0, 19)
$StorageAccount = (Get-AzStorageAccount | Where-Object{$_.StorageAccountName -eq $StorageAccountName})
# Create the storage account if it doesn't already exist
if ($StorageAccount -eq $null) {
if ($StorageResourceGroupLocation -eq "") { throw "The StorageResourceGroupLocation parameter is required on first run in a subscription." }
$StorageResourceGroupName = 'ARM_Deploy_Staging'
New-AzResourceGroup -Location "$StorageResourceGroupLocation" -Name $StorageResourceGroupName -Force
$StorageAccount = New-AzStorageAccount -StorageAccountName $StorageAccountName -Type 'Standard_LRS' -ResourceGroupName $StorageResourceGroupName -Location "$StorageResourceGroupLocation"
}
New-AzStorageContainer -Name $StorageContainerName -Context $StorageAccount.Context -ErrorAction SilentlyContinue *>&1
Set-AzStorageBlobContent -Container $StorageContainerName -File "$ArtifactsStagingDirectory\$createUIDefFile" -Context $storageAccount.Context -Force
$uidefurl = New-AzStorageBlobSASToken -Container $StorageContainerName -Blob (Split-Path $createUIDefFile -leaf) -Context $storageAccount.Context -FullUri -Permission r
$encodedurl = [uri]::EscapeDataString($uidefurl)
if ($Gov) {
$target=@"
https://portal.azure.us/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"providerConfig":{"createUiDefinition":"$encodedurl"}}
"@
}
else {
$target=@"
https://portal.azure.com/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"providerConfig":{"createUiDefinition":"$encodedurl"}}
"@
}
Write-Host `n"File: "$uidefurl `n
Write-Host "Target URL: "$target
# launching the default browser doesn't work if the default is Chrome - so force edge here
Start-Process "microsoft-edge:$target"
}
catch {
throw $_
}