Reading Time: 2 minutes

I am pretty sure that you have already have found out that you can run PowerShell scripts or Commands within your VMs using the Azure Portal or the Azure PowerShell or Azure CLI modules.

What if you are working from a shared workstation or a workstation that is not configured with the appropriate modules? Well, you could always use a pure cloud-native tool, the Azure 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 Upload/Download Files button and choose the script file.

Finally, adjust the following one-liner and execute it in order to run your script within 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 

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

Finally, now that your script is ready, adjust the following one-liner and execute it in order to run your script within 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 

Thanks for reading my blog!

Feel free to drop your comment or question below.