Tag: Run

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 Container Instances from the Docker CLI

Run Azure Container Instances from the Docker CLI

Earlier Docker announced the partnership with Microsoft to bring support to run Azure Container Instances (ACI) from the Docker CLI. Yesterday, Docker announced and released the first Docker Desktop Edge version (2.3.2), which allows you to try out that new feature. Azure Container Instances (ACI) allow you to run Docker containers on-demand in a managed, serverless Azure environment. Azure Container Instances is a solution for any scenario that can operate in isolated containers, without orchestration.

Run Azure Container Instances from the Docker CLI

To be able to run ACI containers using the Docker CLI, Docker expanded the existing docker context command to support ACI as a new backend. To start using this new feature you will need to run Docker Desktop Edge version 2.3.2 and an Azure subscription. You can create a free Azure account with 12 months of free services, $200 credit, and over 25 services which are always free.

Docker Desktop Azure ACI Integration

Docker Desktop Azure ACI Integration

Now you can start your Docker CLI and login to Azure:

docker login azure

After you are logged in, you will need to create a new ACI context. You can simply use “docker context create aci” command and add your Azure subscription and Resource Group, or the CLI will provide you with an Interactive experience.

docker context create aci myazure

With “docker context ls” you can see the added ACI context.

docker context ls
Docker Desktop CLI create Azure Container Instance ACI Context Integration

Docker Desktop CLI create Azure Container Instance ACI Context Integration

Now you can switch to the newly added ACI context.

docker context use myazure

Now you can start running containers directly on Azure Container Instance using the Docker CLI.

docker run -d -p 80:80 mycontainer

You can also see the running containers using docker ps.

docker ps
Run Azure Container Instances from the Docker CLI

Run Azure Container Instances from the Docker CLI

This will also show you the public IP address of your running container to access it. In my example I used a demo container, however, you can also use your own container which you pushed to a container registry like Docker Hub.

You can also run multi-container applications using Docker Compose. You can find an example for that here.

Try Azure Container Instances from the Docker CLI

This new experience is now available as part of Docker Desktop Edge 2.3.2 . To get started, simply download the latest Edge release or update if you are already on Desktop Edge and create a free Azure account with 12 months of free services, $200 credit, and over 25 services which are always free.

Conclusion

I hope this gives you a short overview of how you can use the Docker CLI to directly run Docker containers in Azure Container Instances (ACI). If you have any questions, feel free to leave a comment.

There are also many other great examples like running Docker Linux containers on Windows, using the Windows Subsystem for Linux 2 (WSL 2).



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.



Run Remote Powershell Commands on multiple standalone Computers

Powershell Header

With this little Powershell Script you can run Powershell Commands on multiple Remotehosts even if those are not in an Active Directory.

# Config
$Servers = @("Server01", Server02)
$Cred = Get-Credential # Add Credentials for all Servers (Domain or non-Domain)
 
# Run Command (for example Get-Service | Where-Object {$_.Name -eq "BITS"}
foreach ($Server in $Servers) {
	Invoke-Command -ComputerName $Server -Credential $Cred {Get-Service | Where-Object {$_.Name -eq "BITS"}}
}

Important:

You have to enable Powershell Remoting on the Remotehost with Enable-PSRemoting