Tag: Azure PowerShell

PowerShell Predictive IntelliSense

PowerShell Predictive IntelliSense

2020 must have been a busy year because I missed one of the greatest new PowerShell features called Predictive IntelliSense. Back in November 2020, Jason Helmick announced PowerShell PSReadLine 2.1 with Predictive IntelliSense.

Update: PSReadLine version 2.2 is now general available.

One of the first things you learn when using a shell usually is tab completion. Tab provides automatic help when you are typing a command. However, we all know that the world around us gets increasingly complex. For example, the Azure PowerShell module offers over 4000 cmdlets with on average 10 parameters each. While tab-completion often is very helpful, wouldn’t it be great if the shell predicts what I am trying to do, based on my history or even with artificial intelligence (AI) pulled from the documentation? PowerShell Predictive IntelliSense is here to help with exactly that.

PowerShell Predictive IntelliSense
PowerShell Predictive IntelliSense

PowerShell Predictive IntelliSense uses my local command history and suggests the command I want to use. And with the latest version of PSReadLine 2.2.2 it can have additional plugins. These additional providers enhance predictions by providing domain-specific command and task completions, for example, for Azure PowerShell commands.

Keyboard shortcuts

Key bindings control cursor movement and additional features within the prediction. To support ListView, additional key bindings have been added to the Windows edit mode.

F2 is bound with SwitchPredictionView by default for switching between the InlineView and ListView.

Ctrl+z will revert to the original line when a list item is selected and keep the list view.

Escape will revert to the original line, whether a list item is selected, and clear the list view.

UpArrow and DownArrow are used to select an item in the ListView. To navigate history commands while the ListView is present, first press Escape to clear the ListView, then use UpArrow and DownArrow.

With Alt+A you can jump from parameter input to parameter input.

Get started with PowerShell Predictive IntelliSense

Predictive IntelliSense is implemented in the PowerShell engine and presented through the PSReadLine module. You can use the current version, which comes with PowerShell 7.2, or you can use some additional features with the latest beta release.

PSReadLine 2.2.2 + History Based Prediction

PowerShell Predictive IntelliSense InlineView
PowerShell Predictive IntelliSense InlineView

History-based predictions is available in the following versions:

Availability:

  • PSReadLine 2.2.2 currently available for download from PSGallery

Supported PowerShell versions:

Install PSReadLine 2.2.2:

Install-Module PSReadLine -Force

By default Predictive IntelliSense is disabled, you can enable it by running the following commands:

Set-PSReadLineOption -PredictionSource History

PSReadLine Plugin Prediction

PowerShell Predictive IntelliSense ListView
PowerShell Predictive IntelliSense ListView with History and Plugin

Version 2.2.2 brings ListView and a prediction plugin.

Availability:

  • PSReadLine 2.2.2 currently available for download from PSGallery

Supported PowerShell versions for ListView (History-based predictions only):

Supported PowerShell versions for the plugin subsystem (History and plugin predictions):

  • PowerShell 7.2
Install-Module PSReadLine -Force

By default, Predictive IntelliSense is disabled, you can enable it by running the following commands:

Set-PSReadLineOption -PredictionSource HistoryAndPlugin
#OPTIONAL you can also enable ListView
Set-PSReadLineOption -PredictionViewStyle ListView

One of the currently available plugins is Az Predictor, which helps you predict Azure PowerShell cmdlets. I will show you more about Az Predictor next week.

But wait there is more!

In his blog post, Jason Helmick shows even more functionality like:

  • Change the Color for Predictions using.
    Set-PSReadLineOption -Colors @{ InlinePrediction = ‘#8A0303’}
    Set-PSReadLineOption -Colors @{ InlinePrediction = ‘#2F7004’}
    Set-PSReadLineOption -Colors @{ InlinePrediction = “$([char]0x1b)[36;7;238m”}
  • Key Bindings for Predictions (List of additional suggested key bindings defined in PSReadLine SamplePSReadLineProfile.ps1)
  • and much, much more! So make sure you check out his blog post!

PowerShell Predictive IntelliSense Conclusion

I think the PowerShell Predictive IntelliSense feature is one of the best things since sliced bread. It can make you much more productive using PowerShell in so many different ways. And with the additional AI-powered modules, for example, Az Predictor, which kind of reminds me of the Azure CLI “az find” command, will help deal with more complex scenarios.

If you have any questions or comments, feel free to leave a comment below.



Azure VM Run Command Run PowerShell Script

How to Run Scripts in your Azure VM using Run Command

You can access your Azure IaaS virtual machine (VM) in multiple ways like SSH or RDP, depending on your operating system and configuration. However, if you have issues with the RDP or SSH network configuration, you need to have a way to troubleshoot your virtual machine (VM). Luckily Azure offers you different management tools to work with Azure VMs for automation or troubleshooting. With the Run Command can run a PowerShell or shell script within an Azure VM remotely by using the VM agent. This scenario is especially useful when you need to troubleshoot operating system network configurations or user access configuration. For example, it can be convenient to reset RDP configurations on Windows Server virtual machines.

You use Run Command for Azure VMs through the Azure portalREST API, Azure CLI, or PowerShell. Here are some examples:

Azure VM Run Command in the Azure Portal

You can run the command directly from the Azure Portal. In the menu of the Azure VM, you can select Run command. Here you can find some predefined scripts to troubleshoot your Azure VM. In the case of a Windows VM, you will find scripts like configuring RDP port or enable PowerShell remoting. But you can also run your custom PowerShell script.

Azure VM Run Command Run PowerShell Script

Azure VM Run Command Run PowerShell Script

For Linux VMs, you will find predefined options to run a Linux shell script or ifconfig to list the network configuration.



Run Azure PowerShell in a Docker Container Image

Run Azure PowerShell in a Docker Container

Yesterday, the Azure PowerShell team announced the Azure PowerShell Docker Container images. In this post, I want to quickly highlight that announcement and show you how you can download, pull, and run Azure PowerShell in a Docker container image from Microsoft.

But first, let’s talk about why you would want to run an Azure PowerShell in a Docker container. Azure is continuously evolving, and the Azure PowerShell team releases a new version of the Azure PowerShell modules every three weeks. This makes it challenging to maintain a production or development environment up to date and ensuring the smooth execution of scripts. With the Azure PowerShell docker container image, you can quickly run scripts against a specific version of Azure PowerShell.

The team highlights the current scenarios:

  • On the same machine, you can run scripts that are using a different version of Az with no conflicts.
  • You can test a script against a different version of Az with no risks.
  • You can run the latest container image interactively.


Reset RDP and Admin Password Azure VM

How to Reset RDP and Admin Password of an Azure VM

I think we all had that experience where we suddenly couldn’t use Remote Desktop Services (RDP) to access our Windows Server anymore. Luckily, if this happens to an Azure virtual machine (VM), we can use the VMAccess extension to reset the RDP configuration as well as the password of the Azure VM. You can reset the RDP configuration or the Azure virtual machine password using the Azure portal or Azure PowerShell.

Reset the administrator password of an Azure VM 🔓

To reset the password of an Azure VM, you can use the Azure portal or Azure PowerShell. If you take the portal path, log in to the Azure portal, go to the Azure VM, you want to reset the password. Under Support + Troubleshooting, click on Reset Password, and follow to the Reset Password wizard to update the credentials. Note that this is not supported for Active Directory Domain Controllers.

Reset Administrator Password of an Azure VM

Reset Administrator Password of an Azure VM

If you want to use Azure PowerShell, you can run the following commands:

$SubID = "SUBID" 
$RgName = "RESOURCE GROUP NAME" 
$VmName = "VM NAME" 
$Location = "LOCATION"
 
Connect-AzAccount 
Select-AzSubscription -SubscriptionId $SubID 
Set-AzVMAccessExtension -ResourceGroupName $RgName -Location $Location -VMName $VmName -Credential (get-credential) -typeHandlerVersion "2.0" -Name VMAccessAgent

This should help you to reset the password of an Azure Virtual Machine (VM) if you lost access to it. If you want to know more, read the following troubleshooting article on Microsoft Docs.

Reset RDP configuration 👩‍💻

If you can access your Azure Virtual Machine using RDP, you can reset the configuration, and this will enable Remote Desktop service in the VM and create a firewall rule for the default RDP port 3389. To reset the Remote Desktop Service (RDP) configuration, you again login to the Azure portal, select the virtual machine you want to reset the RDP configuration. Under Support + Troubleshooting, click on Reset Password, on the new blade select Reset configuration only, and click on update.

Reset Remote Desktop Services RDP of an Azure VM

Reset Remote Desktop Services RDP of an Azure VM

There is also an Azure PowerShell command available to do this:

$SubID = "SUBSCRIPTION ID" 
$RgName = "RESOURCE GROUP NAME" 
$VmName = "VM NAME" 
$Location = "LOCATION"
 
Connect-AzAccount 
Select-AzSubscription -SubscriptionId $SubID 
Set-AzVMAccessExtension -ResourceGroupName $RgName" -VMName $VmName" -Name "myVMAccess" -Location $Location -typeHandlerVersion "2.0" -ForceRerun

I hope this gives you an overview of how you can Reset your Remote Desktop Service of an Azure Virtual Machine (VM) if you lost access to it. If you want to know more, read the following troubleshooting article on Microsoft Docs. You can also use Azure PowerShell in Cloud Shell.

If you want to know more about how you migrate your virtual machines to Azure, check out my blog post about Azure Migrate.

 



Mastering Azure using Cloud Shell Session

Video: Mastering Azure using Cloud Shell, PowerShell and Bash!

At the NetWork 9 Conference in Neum and at the Global Azure Bootcamp in Switzerland, I presented my session about Mastering Azure using Cloud Shell. Since I got a lot of requests for the session to be online, I recorded my presentation and made it available for everyone. The presentation is a live demo and summary of my blog post “Mastering Azure with Cloud Shell“, which gives you an overview about the Cloud Shell and some of the advanced stuff you can do.

In the session you learn:

I hope you enjoy watching it and let me know what you think in the comments.



Mastering Azure with Cloud Shell

Mastering Azure with Cloud Shell

There are multiple ways to interact and manage resources in Microsoft Azure. You can use the Azure Portal or command line tools like the Azure PowerShell module or the Azure CLI, which you can install on your local machine. However, to set up a cloud management workstation for administrators and developers can be quite a lot of work. Especially if you have multiple computers, keeping consistency between these machines can be challenging. Another challenge is keeping the environment secure and all the tools up to date. The Azure Cloud Shell addresses this any many more things.

Cloud Shell is not brand new, Microsoft announced Cloud Shell at Build 2017. This blog post is about how you can master Azure with Cloud Shell and give you an overview of the possibilities of Cloud Shell.

 

What is Cloud Shell

Cloud Shell Azure Portal

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.

Cloud Shell Bash and PowerShell

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.



Azure Cloud Shell

Azure Cloud Shell – shell.azure.com and in Visual Studio Code

Back in May Microsoft made the Azure Cloud Shell available in the Microsoft Azure Portal. Now you can use it even quicker by just go to shell.azure.com. First you login with your Microsoft account or Work and School account, and if your account is in multiple Azure Active Directory tenants, you select the right tenant and you will be automatically logged in. So even if you are on a PC where you can not install the Azure CLI or the Azure PowerShell module, you can still easily fire up a shell where you can run the Azure CLI, Azure PowerShell and other CLI tools like Docker, Kubectl, emacs, vim, nano, git and more.

In addition you can also open up Azure Cloud Shell directly from Visual Studio Code

Azure Cloud Shell Visual Studio Code

With that, enjoy your holidays and I wish you a good start in the new year!



Azure PowerShell Module

Microsoft Azure PowerShell 4.0

Microsoft not only announced the Azure Cloud Shell, Microsoft also announced the Azure PowerShell 4.0. The new Azure PowerShell 4.0.0 adds various improvements and fixes across multiple Azure resources. Focusing on features like Container Service, Service Fabric, Container Registry, SQL, Storage, Replay and a lot more.

You can install the cmdlets via your favorite Azure PowerShell installation path indicated in the Azure PowerShell 4.0.0 release notes.

Also check out my new blog: Mastering Azure using Cloud Shell



Azure Cloud Shell

Microsoft Azure Cloud Shell

Today at the Microsoft Build Conference, Microsoft announced the Azure Cloud Shell. The Azure Cloud Shell is a browser-based shell experience to manage and develop Azure resources.

Azure 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. Today it gives you a variety of different tools directly from your web browser in the Azure Portal.

This gives Azure Administrators an easy admin environment to manage resources as well as third-party applications. In the background Microsoft runs thousands of isolated containers, ready for you to use. Microsoft takes care of keeping this container up to date, so you can focus on your administrator tasks. The usage is free, the only thing you will need to pay, are the storage cost for your container and the things you store on the Azure File Share.

Linux shell interpreter

  • Bash
  • sh

Azure tools

  • Azure CLI 2.0 and 1.0

Text editors

  • vim
  • nano
  • emacs

Source control

  • git

Build tools

  • make
  • maven
  • npm
  • pip

Containers

  • Docker
  • Kubectl
  • DC/OS CLI

Databases

  • MySQL client
  • PostgreSql client
  • sqlcmd Utility

Other

  • iPython Client

It also looks like PowerShell will be available later, hopefully it will arrive soon. Microsoft also announced Azure PowerShell 3.0. If you want to learn, check out my blog post: Mastering Azure with Cloud Shell



Install Azure PowerShell Az Module

How to Install the Azure PowerShell Module

This blogs post describes how you can install the Azure PowerShell module. Microsoft a couple of weeks ago released version one of their new Azure PowerShell module on .NET Core called the Az module. The Az module will replace the AzureRM module over time. however, the AzureRM module is still supported. The new Az module is a cross-platform module.

Well if you are working with Microsoft Azure you may need the PowerShell Modules for automation and some settings which are only available in PowerShell. With the latest releases you can install the Azure PowerShell Module using the package management in PowerShell, and install the Azure PowerShell module form the PowerShell Gallery.

Az module features

  • Az is a replacement for AzureRM and AzureRM.Netcore.
  • Runs on PowerShell 5.1 and PowerShell Core.
  • It is always up to date with the latest tooling for Azure services.
  • Az ships in Cloud Shell.
  • It shortens and normalizes cmdlet names. All cmdlets use “Az” as their noun prefix.
  • Az will simplify and normalize module names. Data plane and management plane cmdlets for each service will use the same Az module.
  • It ships with new cmdlets to enable script compatibility with AzureRM (Enable/Disable-AzureRmAlias).

Supported platforms

  • PowerShell 5.1 – Windows 7 or greater with .Net Framework 4.7.2 or greater installed
  • PowerShell Core 6.0 – Windows, Mac OS, Linux
  • PowerShell Core 6.1 – Windows, Mac OS, Linux

Install Azure PowerShell module

For me using the PowerShell Package Management and the PowerShell Gallery is may the easiest and fastest way to install it. In Windows 10 or a computer with the Windows Management Framework 5 installed, you can use the following PowerShell cmdlets to install it.

You should not install Az side-by-side with AzureRM. Remove all AzureRM modules before installing Az.

 
Install-Module Az

You can also update the AZ module using the following command:

 
Update-Module Az

And you can use the following command to login:

 
Connect-AzAccount

You can also see the Azure PowerShell Modules and versions using the PowerShell Package Management:

 
Find-Module -ListAvailable *Az*

AzureRM compatibility

If you would like to run scripts developed for AzureRM using Az, use the Enable/Disable-AzureRmAlias cmdlets to add or remove aliases from AzureRM cmdlets to Az cmdlets.

This can be enabled and disabled:

 
Enable-AzureRmAlias
 
Disable-AzureRMAlias

Run Azure PowerShell from Cloud Shell

You can also run the latest Azure PowerShell module version directly from Cloud Shell, with no need to install it.

This blog post was updated with the release 1.0.0 of the Azure Az module based on .NET Core. You can find more about the new Azure PowerShell module on the GitHub repo.

Also check out my blog post: Mastering Azure using Cloud Shell