Reading Time: 2 minutes

Azure Cloud Shell is a browser-based shell environment that allows you to manage Azure resources from anywhere. One of its useful features is the ability to run PowerShell scripts or commands on your Azure Windows virtual machines (VMs) directly from Cloud Shell.

So let’s quickly go through 2 different scenarios in which we could use Cloud Shell to run our scripts or commands straight to your Azure VMs.

Scenario number 1: Upload and run a PowerShell Script

Launch Cloud Shell straight from the Azure Portal, click on the Upload/Download Files button, and choose the script file.

To run your script on your Azure VM, make changes to the one-liner below and execute it as your final step.

Invoke-AzVMRunCommand -ResourceGroupName 'name-of-the-resourcegroup-where-the-vm-resides' -Name 'name-of-your-vm' -CommandId 'RunPowerShellScript' -ScriptPath 'name-of-the-ps-script-located-in-storageaccount-of-cloudshell' -Verbose 

Scenario number 2: Create a PowerShell script straight from the Cloud Shell using Monaco browser-based editor

Lastly, make adjustments to the following one-liner and execute it to run your script on your Azure VM.

Invoke-AzVMRunCommand -ResourceGroupName 'name-of-the-resourcegroup-where-the-vm-resides' -Name 'name-of-your-vm' -CommandId 'RunPowerShellScript' -ScriptPath 'name-of-the-ps-script-located-in-storageaccount-of-cloudshell' -Verbose 

This feature can save you time and effort by allowing you to manage your VMs from anywhere without the need for additional tools or software. Whether you’re a sysadmin, developer, or IT professional, this knowledge can help you streamline your workflow and improve your productivity.

Thanks for reading my blog!

Feel free to drop your comment or question below.