Download CLI
az configure configure defaults
enter az login and this will open in browser to enter details, after this step gives an error about authentication
az login –tenant yourtenantid
find tenantid in https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Properties
az account list --query "[].{Name:name, IsDefault:isDefault}"
az account set --subscription "Free Trial"
az account list --query "[].{Name:name, User:user.name}"
az vm list
az logout
az find --search-query "vm"
az vm --help
az account list
az account list --output table
az group list
az network vnet list
az network vnet subnet list -g $resource_group --vnet-name $vnet
az network nsg list -g $resource_group
az network nsg rule list -g $resource_group --nsg-name $nsg
az network nic list
az network nic ip-config list -g $resource_group --nic-name $nic
az network public-ip list -g $resource_group
az vm list -g $resource_group
az vm list -g $resource_group --show-details
Install Azure PowerShell
Connect-AzAccount gives error use tenant id as below
Connect-AzAccount -Tenant d80b5694-0b92-4093-a0bd-473457598969
Get-AzTenant
Get-AzSubscription
Get-AzVM
Get-AzStorageAccount
Get-AzResourceGroup
Get-AzResource
Disconnect-AzAccount
Get-Command -Verb Get -Noun AzVM* -Module Az.Compute
Get-AzResourceGroup
Get-AzResourceGroup -Name “TestRG”
Get-AzResource-ResourceGroupName “TestRG”
New-AzResourceGroup -Name’TestRG’ -Location’northcentral’
Set-AzResourceGroup-Nameexamplegroup-Tag@{ Dept=“IT”; Environment=“Test”
Get-AzPolicyDefinition
Create a policy using JSON and save it as a json file
$definition = New-AzPolicyDefinition-Name denyRegions
-DisplayName “Deny specific regions”` -Policy ‘https://githublocation.com/azurepolicy.rules.json’
$definition = New-AzPolicyDefinition-Name denyCoolTiering
-Description “Deny cool access tiering for storage”` -Policy ‘c:.json’
$rg= Get-AzResourceGroup -Name “ExampleGroup” New-AzPolicyAssignment -Name denyRegions -Scope rg.ResourceId − PolicyDefinitiondefinition
New-AzResourceLock -LockLevel ReadOnly-Lock Notes “Notes about the lock” -LockName “Test-WebSiteLock” -ResourceName “Test-WebSite” ResourceType “microsoft.web/sites”
Get-AzResourceLock -LockName “Test-WebSiteLock” -ResourceName “Test-WebSite” -ResourceType “microsoft.web/sites” -ResourceGroupName “RGWebSite”
Get-StorageAccount
New-AzStorageAccount -ResourceGroupName “teststoragerg” -Name“teststorage1” -Location “eastus” -SkuName“Standard_LRS”
New-AzStorageContainer -ResourceGroupName “teststoragerg” -AccountName“teststorageaccount” -ContainerName “testContainer”
$vmconfig = New-AzVMConfig -VMName “systemname” -VMSize “Standard_D1_v2”
$vmconfig = Set-AzVMOperatingSystem -VM $vmconfig -Windows -ComputerName “systemname” -Credential $cred -ProvisionVMAgent EnableAutoUpdate
$vmconfig = Add-AzVMNetworkInterface-VM $vmconfig -Id $nic.Id
$vmconfig = Set-AzVMSourceImage-VM $vmconfig -PublisherName “publisher_name” -Offer “publisher_offer” -Skus “product_sku” -Version “latest”
New-AzVM-ResourceGroupName “testresourcegroup” -Location “eastus” -VM $vmconfigconfig
Start-AzVM -ResourceGroupName “testresourcegroup” -Name “vmname”
Get/List NetworkingList virtual networks
Get-AzVirtualNetwork-ResourceGroupName “abcresourcegroup”
Get-AzVirtualNetwork-Name “myVNet” -ResourceGroupName “abcresourcegroup”
Get-AzVirtualNetwork-Name “myVNet” -ResourceGroupName “abcresourcegroup” | Select Subnets
Get-AzVirtualNetworkSubnetConfig-Name “mySubnet1” VirtualNetwork $vnet
Get-AzPublicIpAddress-ResourceGroupName “abcresourcegroup”
Get-AzLoadBalancer-ResourceGroupName “abcresourcegroup”
Get-AzNetworkInterface-ResourceGroupName “abcresourcegroup”
Get-AzNetworkInterface-Name “abcNIC” -ResourceGroupName “abcresourcegroup”
Get-AzNetworkInterfaceIPConfig-Name “abcNICIP” -NetworkInterface $nic
$subnet1 = New-AzVirtualNetworkSubnetConfig-Name “abcSubnet1” -AddressPrefix XX.X.X.X/XX
$subnet2 = New-AzVirtualNetworkSubnetConfig -Name “abcSubnet2” AddressPrefix XX.X.X.X/XX
$vnet = New-AzVirtualNetwork-Name “myVNet” -ResourceGroupName “testresourcegroup” -Location $location -AddressPrefix XX.X.X.X/XX -Subnet slsubnet1,slsubnet2
Test-AzDnsAvailability-DomainNameLabel “myDNS” -Location $location
$pip = New-AzPublicIpAddress-Name “myPublicIp” -ResourceGroupName “abcresourcegroup” -DomainNameLabel “myDNS” -Location $location AllocationMethod Dynamic
$frontendIP = New-AzLoadBalancerFrontendIpConfig-Name “myFrontendIP” PublicIpAddress $pip
$beAddressPool = New-AzLoadBalancerBackendAddressPoolConfig-Name “myBackendAddressPool”
$healthProbe = New-AzLoadBalancerProbeConfig-Name “myProbe” RequestPath ‘HealthProbe.html’ -Protocol http -Port 80 -IntervalInSeconds 15 ProbeCount 2
$lbRule = New-AzLoadBalancerRuleConfig-Name HTTP -FrontendIpConfiguration $frontendIP -BackendAddressPool $beAddressPool -Probe $healthProbe -Protocol Tcp -FrontendPort 80 -BackendPort 80
$inboundNATRule = New-AzLoadBalancerInboundNatRuleConfig-Name “myInboundRule1” -FrontendIpConfiguration $frontendIP -Protocol TCP -FrontendPort 3441 -BackendPort 3389
$loadBalancer = New-AzLoadBalancer-ResourceGroupName “abcresourcegroup” -Name “myLoadBalancer” -Location $location -FrontendIpConfiguration $frontendIP InboundNatRule $inboundNATRule -LoadBalancingRule lbRule − BackendAddressPoolbeAddressPool -Probe $healthProbe
$nic1= New-AzNetworkInterface-ResourceGroupName “abcresourcegroup” Name “myNIC” -Location $location -PrivateIpAddress XX.X.X.X -Subnet $subnet2 -LoadBalancerBackendAddressPool $loadBalancer.BackendAddressPools[0] -LoadBalancerInboundNatRule $loadBalancer.InboundNatRules[0]
Remove-AzVirtualNetwork-Name “myVNet” -ResourceGroupName “abcresourcegroup”
Install-ModuleAzureAD
Connect-AzureAD
Disconnect-AzureAD
Get-AzureADUser
Get-AzureADUser-ObjectId “user@abc.com”
Remove-AzureADUser-ObjectId “user@abc.com”
Stop-AzVM -ResourceGroupName “testresourcegroup” -Name “vmname”
Restart-AzVM -ResourceGroupName “testresourcegroup” -Name “vmname”
Remove-AzVM -ResourceGroupName “testresourcegroup” -Name “vmname”