-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
21 lines (21 loc) · 1.2 KB
/
deploy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#parameters
$rgname = 'nested-rg'
$vmName = 'myVM'
$location = 'swedencentral'
$adminUsername = 'localadmin'
$adminPassword = Read-Host -Prompt 'Input the user password' -AsSecureString
#Deploy ResourceGroup
Write-Output -InputObject "Initiating ResourceGroup...$(get-date)"
New-AzResourceGroup -Name $rgname -Location $location
Start-Sleep -Seconds 5
#Deploy Environment
Write-Output -InputObject "Initiating Resources...$(get-date)"
New-AzResourceGroupDeployment -Name 'NestedVmDeploy' -ResourceGroupName $rgname -TemplateFile .\main.bicep -Location $location -vmName $vmName -adminUsername $adminUsername -adminPassword $adminPassword
Start-Sleep -Seconds 5
$resizecommand = 'Resize-Partition -DriveLetter C -Size $(Get-PartitionSupportedSize -DriveLetter C).SizeMax'
az vm run-command invoke --command-id RunPowerShellScript -g $rgname --name $vmName --scripts $resizecommand
#Enable Hyper-v feature
Write-Output -InputObject "Initiating Hyper-V install...$(get-date)"
$command = 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart'
az vm run-command invoke --command-id RunPowerShellScript -g $rgname --name $vmName --scripts $command
az vm restart -g $rgname -n $vmName