-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsideload-uiandtemplate.ps1
52 lines (40 loc) · 2.5 KB
/
sideload-uiandtemplate.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
#Requires -Version 3.0
#Requires -Module @{ModuleName='Az.Storage';ModuleVersion='1.1.1'}
#Requires -Module @{ModuleName='Az.Accounts';ModuleVersion='1.2.1'}
#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)
$StorageAccountName = 'uidefinitiontest'
$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 = 'p-rg-uidefinitiontest'
$tags = @{Purpose='Test UI Definiton file'}
New-AzResourceGroup -Location "$StorageResourceGroupLocation" -Name $StorageResourceGroupName -Tag $tags -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)
$target=@"
https://portal.azure.com/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"initialData":{},"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"
$global:target|set-clipboard
}
catch {
throw $_
}