PROBLEM:
Azure portal provides a nice interactive interface to get details about configuration or drop/create resources. Sometimes, we need to connect Azure with Powershell to automate certain tasks. It can be useful if you are making your own inventory of Azure VMs, Disks allocated or performing a check whether certain resources has been created. Once resources dropped can never be recovered, to avoid human mistakes, it is always advisable to make your own repository to have a capability to recreate resources.
Azure CLI provides different options to get the inventory details and it also provides several capabilities that Azure Powershell might not have. In this article, I will over the details about Azure Powershell AZ modules.
How to connect to Azure Powershell from you desktop?
SOLUTION:
Assuming you have an Azure account (Free or Paid or Pay-As-You-Go).
1. Install Azure Powershell
To install, Azure Powershell make sure your machine is able to connect to Azure. If it is connected, there could still be a situation where it will not connect to Azure due to firewall blocking or server not allowing to download or perform certain tasks.
1) You can connect to http://portal.azure.com first.
- If it does not connect, try to add in Internet Explorer trusted servers list that must have little low checks.
- Gradually add links that it denies.
- If you are not sure what link is blocked. You can press F11 and try to see the blocked URL in console.
2) IE, Edge and Chrome allows connecting. But I prefer Chrome due to obvious reasons.
3) Once connection is fine, check the modules installed on machine using below command:
get-module -ListAvailable | where { $_ -match "Az." }
-OR-
You can check very easily in Powershell ISE.
[4] If not found, you can run command like below:
Install-Module -Name Az -AllowClobber -Scope AllUsers
2. Connect Azure
Run the command like below:
A pop-up will come. Enter your credentials.
3. Try few commands to confirm.
Get-AzResourceGroup
Get-AzRM
Get-AzStorageAccount
That's all! You can find so many Powershell scripts over internet. Try them.
From installing VM to shutting down, everything that you can do with GUI can be done with Azure Powershell.
I will provide many script that I wrote for my purposes.\
Thanks !!!