Azure Automation - Run scripts using Azure commands or PowerShell commands

Kenneth 61 Reputation points
2022-08-18T22:50:06.967+00:00

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.
1,131 questions
0 comments No comments
{count} votes

Accepted answer
  1. Maxim Sergeev 6,566 Reputation points Microsoft Employee
    2022-08-18T23:32:44.267+00:00

    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. https://learn.microsoft.com/en-us/windows/win32/winrm/installation-and-configuration-for-windows-remote-management

    Invoke-AzVMRunCommand is an Azure-based commandlet, it's native for Azure and it's required to have Azure Agent (https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-windows) 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: Most helpful