SOLVED – Azure Automation – Run scripts using Azure commands or PowerShell commands
Problem – 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?
You May Also Like: SOLVED – How To Get All Data From Last 5 Minutes in SQL
SOLUTION
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://docs.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://docs.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 cloud 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. The decision is in your hands.
You May Also Like: SOLVED – How To Update Connection Policy Of Synapse Dedicated SQL Pools
We hope the solutions in the above-mentioned article were helpful. Feel free to share your views with us.