There are many experiences and possibilities to manage your Microsoft Azure resources, one of them being the command line experience using the Azure CLI or Azure PowerShell. In this blog post we are going to have a look at 6 tips & tricks for managing your Microsoft Azure resources using the command line with Azure PowerShell and the Azure CLI.
Here are 6 command line Azure PowerShell and CLI tips & tricks for Microsoft Azure you should know about:
Az Predictor – Using AI-powered Intelligent context-aware command completion for Azure PowerShell
Sometimes it is hard to find the right commands and parameters when you want to run commands in the terminal. The Az Predictor module for Azure PowerShell is a great tip and trick which makes it easy to get not only suggestions based on your history of commands, but also AI-powered intelligence suggestions for your Azure PowerShell commands.
Az Predictor is using the subsystem for PowerShell Predictive Intelligence in the PSReadline module. You can use a list or inline view and you can also switch between these two views using the F2
key. To jump from one parameter to another you can use ALT+A
which makes it super easy to change the parameters of the command.
To leverage the Az Predictor module, you will need to run PowerShell 7.2 or higher, and PSReadline 2.2.2 or higher. To learn more about the Az Predictor module and PowerShell Predictive Intelligence, check out my blog post.
Az Find – Use AI to find az commands
Another great Azure CLI tip is the Az Find command. The az find command provides you with example commands based on Azure documentation and usage patterns of the Azure CLI and Azure Resource Manager users.
You can see that I was looking for how I can delete an Azure backup or recovery service vault. Since the Azure CLI find command learn from documentation and usage, I not only get the example of deleting an existing Recovery service vault, but it also lets me know of other related examples that might come in handy. To learn more about the Azure CLI find command, check out my blog post here.
Az Next – AI-powered interactive assistant for the Azure CLI
Az next is designed to guide users through their scenarios or sequence of jobs-to-be-done in tool, so that they can remain focused and avoid unnecessary external documentation searches. Az next adopts the latest design guidelines and should help making the Azure CLI more approachable for all users, including beginners.
There are two scenarios which are currently supported. The first one is a simple walkthrough for the next commands as soon as you execute az next. After that, the Azure CLI will return a set of command options, which are highly likely to come after your last command. This is super helpful if you are running a sequence of commands, the Azure CLI will provide you with predictive recommendations.
The second one is the end-to-end scenario walkthrough with the aim to help you achieve a specific scenario in mind. In these case the options show up in form of a summary instead of an explicit command, and the tool will guide you through individual command completion.
To learn more about az next, check out my blog post here.
Cloud Shell – Run your commands in the cloud
Azure Cloud Shell is an interactive, authenticated, browser-accessible shell for managing Azure resources. It provides the flexibility of choosing the shell experience that best suits the way you work, either Bash or PowerShell.
Cloud Shell offers a browser-accessible, pre-configured shell experience for managing Azure resources without the overhead of installing, versioning, and maintaining a machine yourself. Azure Cloud Shell is assigned per unique user account and automatically authenticated with each session. This makes it a private and secure environment.
You get a modern web-based command line experience which can be accessed from several endpoints like the Azure Portal, shell.azure.com and the Azure mobile app, Visual Studio Code or directly in the Azure docs.
In the backend, Azure uses containers and automatically attaches an Azure File Share to the container. You can store the data on it, so your data is persistent. This persists your data across different Cloud Shell sessions.
You can choose your preferred shell experience. Cloud Shell supports Bash and PowerShell and included your favorite third-party tools and standard tools and languages. If something like a module is missing, you can add it.
There is much more you can do, check out my blog called Mastering Azure with Cloud Shell to learn some more unique tips and tricks to manage Azure using Azure Cloud Shell.
One thing I also want to mention is that you can also run Azure PowerShell or Azure CLI in Cloud Shell directly from your mobile phone, using the Azure mobile app!
Azure Automation – Schedule your scripts and runbooks in the cloud
Sometimes you want to schedule your scripts to run at specific times. With Azure Automation you can schedule your scripts to be run on Azure workers or on your own servers running in Azure, on-premises, or at other cloud providers.
- Schedule and Run PowerShell Scripts for Azure VMs using Azure Automation
- Run PowerShell Scripts with Azure Automation Hybrid Workers on-premises using Azure Arc
Azure Automation delivers a cloud-based automation, operating system updates, and configuration service that supports consistent management across your Azure and non-Azure environments. It offers a couple of distinctive features, in this blog we are going to use the process automation feature, which allows you to run automation inform of PowerShell runbooks. We are going to use Azure Automation to schedule the scripts to run on Azure VMs.
Az Arc SSH – Connect to any server using SSH running anywhere
With Azure Arc, you can remotely manage your Linux and Windows Servers using the Azure control plane and management services, such as Azure Policy, Update Management, Security Center, Azure Monitor, and many more. This allows you to manage servers running on-premises, at the edge, or in mutlicloud environments at scale. However, in some cases, you will need to have direct access to your servers for troubleshooting, for example using an SSH connection. In many of these hybrid and mutlicloud environments, direct network connectivity can be a challenge, which is why you now can get SSH access to your Linux and Windows Servers running anywhere using Azure Arc enabled servers.
SSH access to Azure Arc-enabled servers offers the following benefits:
- Create interactive and automated SSH connections to Arc-enabled Servers
- Securely access hybrid servers without any additional ports or a public IP address
- Access to Windows and Linux machines
- Leverage different authentication options: AAD login based on RBAC roles (Linux only), Key-based authentication, and username & password authentication
- Connect as a local user or as an Azure user
- Connect with existing SSH clients using a config file
- Connect to servers using Azure Cloud Shell
- Leverage existing workflows & scripts for Azure IaaS Virtual Machines on Arc-enabled Servers
To learn more, check out my blog post: SSH access to servers running anywhere using Azure Arc
What are your favorite Azure command line tips and tricks?
These are some of my favorite Azure command line tips and tricks for the Azure CLI and Azure PowerShell. Do you have any tips and tricks? Let me know in the comments below!
Tags: Az Find, Az Next, Az Predictor, Azure, Azure Automation, Azure CLI, Cloud, Cloud Shell, command line, Microsoft, Microsoft Azure, PowerShell, SSH, Tips, Tricks, Windows Server Last modified: December 16, 2022
I like Invoke-AzVMRunCommand, what it actually does is invoking a command on a Remote VM, it is great if you like to configure VM’s after deployment, Yesterday finished a task to create a self hosted ADF Runtime. Instead of having to update/maintain the machine, we can now just destroy and recreate it with the latest Windows Image, we also don’t have to use a backup vault in case the machine gets corrupted.