Azure Automation - Run scripts using Azure commands or PowerShell commands

Kenneth 61 Reputation points

I am looking to port production jobs into Azure automation. The goal would be to schedule maintenance from scripts held in a shared drive on all computers in that domain. Using Azure, I could use the Invoke-AzVMRunCommand cmdlet to accomplish this task. Powershell also natively supports running scripts remotely with the Invoke-Command cmdlet.

Is there any particular benefit in using one cmdlet as opposed to another? Invoke-Command assumes you have open communication with the target host, but that is a given in my case. Are there any other drawbacks to using Invoke-Command? What about Invoke-AzVMRunCommand?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
813 questions
0 comments No comments
{count} votes

Accepted answer
  1. Maxim Sergeev 6,546 Reputation points Microsoft Employee

    Hi @Kenneth ,

    Invoke-Command is a native commandlet to run your commands over WinRM (Windows Remote Management). It works over the WinRM protocol through port 5595 by default.

    Invoke-AzVMRunCommand is an Azure-based commandlet, it's native for Azure and it's required to have Azure Agent ( on this machine (by default, standard Azure VM machines have it) because it works through the agent, not WinRM.

    Now, summarizing the above, if you plan to invoke your powershell scripts on-premises or in another clouds in the same network - WinRM is a more universal approach (invoke-command). But if you don't want to open WinRM ports or your workloads will be hosted in Azure only, Invoke-AzVMRunCommand could be better. Decision is on your hands.

0 additional answers

Sort by: Newest