I have a lot of VMs I want to run a maintenance script against. I’d like to do it from a Runbook which will iterate over all the VMs and do an Invoke-AzVMRunCommand to run a command in each in turn.
I uploaded the script to be run in the command to the same automation account as the Runbook but I can’t see how to reference it.
I found someone else who’s done the same thing and they say:
when you are using the command id “RunPowerShellScript”, the script needs to exist in your file system.
https://www.hernanjlarrea.com/index.php/azure-native-remoting-options-for-your-iaas-resources/
Does this mean the script to be run needs to be on each VM? Can I do it this way or do I need to use a script block?
Edit: turns out you need to load it into memory first. To prevent it from being executed (dot sourcing will do this) I did:
if ($false) {./filetobecalled.ps1}
…