Welcome Forums General PowerShell Q&A Calling Powerhsll using Invoke-AzVMRunCommand in a runbook

Viewing 1 reply thread
  • Author
    • #190522
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      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.

      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}

      Invoke-AzVMRunCommand …-ScriptPath ‘./filetobecalled.ps1’
    • #190723
      Topics: 3
      Replies: 182
      Points: 964
      Helping Hand
      Rank: Major Contributor

      You can keep the script file in any storage account and then call it from there using Invoke-AzVMRunCommand

Viewing 1 reply thread
  • You must be logged in to reply to this topic.