PowerShell in Azure with example to create a VM

- Install Latest powershell from Microsoft website
- On PowerShell CLI
- Check Version
$PSVersionTable.PSVersion
Get-InstalledModule -Name Az -AllVersions | select Name,Version- Connect to account
- Connect-AzAccount – it will prompt to enter code in URL to have you logged in CLI.
- Change Subscription
Get-AzSubscription- Change to another one
$context = Get-AzSubscription -SubscriptionID xxxxxxx-xxxxx-xxxx-8c74-xxxxxxxSet-AzContext $context
Creating a VM In powershell
Get-AzResourceGroup - list of existing ResourceGroupsNew-AzResourceGroup -Name resGRP0405 -Location EastUSNew-AzVM -ResourceGroupName "resGRP0405" -Name "vm0405" -Location "EastUS" -VirtualNetworkName "vnet0405" -SubnetName "default" -SecurityGroupName "secGRP0405" -PublicIpAddressName "myipaddr" -OpenPorts 80,443,3389It will ask for a password for the VM which you want to set, provide the same.Stop-AzVM -ResourceGroupName "resGRP0405" -Name "vm0405"Start-AzVM -ResourceGroupName "resGRP0405" -Name "vm0405"
