Microsoft Azure (AZ-104): PowerShell Script / Azure CLI

az group create 
--name CreateVNetQS-rg
--location eastus
az network vnet create 
--name myVNet
--resource-group CreateVNetQS-rg
--subnet-name default
az vm create 
--resource-group CreateVNetQS-rg
--name myVM1
--image UbuntuLTS
--generate-ssh-keys
--public-ip-address myPublicIP-myVM1
--no-wait
$diskConfig = New-AzDiskConfig 
-Location "EastUS"
-CreateOption Empty
-DiskSizeGB 128
$dataDisk = New-AzDisk 
-ResourceGroupName "myResourceGroupDisk"
-DiskName "myDataDisk"
-Disk $diskConfig
$vm = 
Get-AzVM
-ResourceGroupName "myResourceGroupDisk"
-Name "myVM"
$vm = Add-AzVMDataDisk     
-VM $vm
-Name "myDataDisk"
-CreateOption Attach
-ManagedDiskId $dataDisk.Id
-Lun 1
Update-AzVM 
-ResourceGroupName “myResourceGroupDisk”
-VM $vm
az vmss scale 
--resource-group myResourceGroup
--name myScaleSet
--new-capacity 5
$role = Get-AzRoleDefinition "Virtual Machine Contributor"
$role.Id = $null
$role.Name = "Virtual Machine Operator"
$role.Description = "Can monitor and restart virtual machines."
$role.Actions.Clear()
$role.Actions.Add("Microsoft.Storage/*/read")
$role.Actions.Add("Microsoft.Network/*/read")
$role.Actions.Add("Microsoft.Compute/*/read")
$role.Actions.Add("Microsoft.Compute/virtualMachines/start/action")
$role.Actions.Add("Microsoft.Compute/virtualMachines/restart/action")
$role.Actions.Add("Microsoft.Authorization/*/read")
$role.Actions.Add("Microsoft.ResourceHealth/availabilityStatuses/read")
$role.Actions.Add("Microsoft.Resources/subscriptions/resourceGroups/read")
$role.Actions.Add("Microsoft.Insights/alertRules/*")
$role.Actions.Add("Microsoft.Support/*")
$role.AssignableScopes.Clear()
$role.AssignableScopes.Add("/subscriptions/00000000-0000-0000-0000-000000000000")
$role.AssignableScopes.Add("/subscriptions/11111111-1111-1111-1111-111111111111")
New-AzRoleDefinition
-Role $role
Move-AzResource -DestinationSubscriptionId
NOT Move-VMResource!!!
New-AzResourceGroup 
-Name 'CreatePubLBQS-rg'
-Location 'eastus'
$publicIp = Get-AzPublicIpAddress 
-Name 'myPublicIP'
-ResourceGroupName 'CreatePubLBQS-rg'
az network public-ip create
--resource-group CreatePubLBQS-rg
--name myPublicIP
--sku Standard
$feip = New-AzLoadBalancerFrontendIpConfig 
-Name 'myFrontEnd'
-PublicIpAddress $publicIp
az network lb create
--resource-group CreatePubLBQS-rg
--name myLoadBalancer
--sku Standard
--public-ip-address myPublicIP
--frontend-ip-name myFrontEnd
--backend-pool-name myBackEndPool
Get-AzStorageAccountNetworkRuleSet 
-ResourceGroupName "myresourcegroup"
-AccountName "mystorageaccount").IPRules
Add-AzStorageAccountNetworkRule 
-ResourceGroupName "myresourcegroup"
-AccountName "mystorageaccount" -IPAddressOrRange "16.17.18.19"
az storage account create 
--name <storage-account>
--resource-group <resource-group>

--location <location>
--sku Standard_ZRS
--encryption-services blob
az storage container create 
--account-name <storage-account>
--name <container>

--auth-mode login
az vm deallocate
--resource-group <>
--name demovm
az vm generalize
--resource-group <>
--name demovm
az image create
--resource-group <>
--name <imageName>
--source demovm
az network dns record-set a add-record 
--resource-group myresourcegroup
--zone-name contoso.com
--record-set-name www
--ipv4-address 1.2.3.4
az network dns record-set a add-record
--resource-group myresourcegroup
--zone-name contoso.com
--record-set-name "@"
--ipv4-address 1.2.3.4
az role definition create 
--role-definition @newrole.json

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
goay xuan hui

goay xuan hui

A food lover, a cyber security enthusiast, a musician and a traveller, so you will see a mix of different contents in my blog. ☺️