powershellazurevirtual-machineazure-cli2runcommand

Using the 'az vm run-command' with a .ps1 file


I have an issue with the az vm run-command.

I have got it working inline as follows:

$resource_name="winsecagentdev2"
$resource_group="russellmccloydev"

and:

az vm run-command invoke `
-g "${resource_group}" `
-n "${resource_name}" `
--command-id 'RunPowerShellScript' `
--scripts "Write-Output 'testing russ'"

It works.

But when I try to use a .ps1 file:

az vm run-command invoke `
-g "${resource_group}" `
-n "${resource_name}" `
--command-id 'RunPowerShellScript' `
--scripts @{'hello.ps1'} `
--parameters @{ "test" = "russell" }

I get this issue:

Enter image description here

The documentation says this:

Enter image description here

So I am kind of stuck.


Solution

  • You need to put the file in your VM and use the format below:

    --scripts "C:\test\hello.ps1"
    

    result:

    enter image description here