forked from ashmind/SharpLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-AzureConfig.ps1
36 lines (29 loc) · 1.38 KB
/
New-AzureConfig.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
Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'
$credential = Get-Credential -Message "Please enter your Azure login details.`r`nA separate user account is recommended."
Login-AzureRMAccount -Credential $credential
$key = New-Object byte[](32)
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($key)
$json = [ordered]@{
UserName = $credential.UserName
Password = $credential.Password | ConvertFrom-SecureString -Key $key
}
$resourceGroups = @(Get-AzureRmResourceGroup)
$index = 0
$options = $resourceGroups | % {
New-Object Management.Automation.Host.ChoiceDescription("&$($index+1). $($_.ResourceGroupName)")
$index += 1
}
$result = $Host.UI.PromptForChoice("Choose Azure resource group", "", $options, 0)
$json.ResourceGroupName = $resourceGroups[$result].ResourceGroupName
$appServicePlans = @(Get-AzureRMAppServicePlan)
$index = 0
$options = $appServicePlans | % {
New-Object Management.Automation.Host.ChoiceDescription("&$($index+1). $($_.Name)")
$index += 1
}
$result = $Host.UI.PromptForChoice("Choose Azure app service plan", "", $options, 0)
$json.AppServicePlanName = $appServicePlans[$result].Name
Set-Content '.\!Azure.config.json' (ConvertTo-Json $json)
Write-Host "Saved config at .\!Azure.config.json. Environment variable for build:"
Write-Host "SET TR_AZURE_PASSWORD_KEY=$([Convert]::ToBase64String($key))"