2

I am running an Azure CLI command in a Windows 10 Professional PowerShell script and I receive this error:

(Conflict) Run command OS type 'Windows' does not match the target OS Linux.

PowerShell version:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1237

The failing PowerShell script:

$ResourceGroup= "Development"
$VmName = "ubuntu-test"

 az vm run-command invoke `
--resource-group $ResourceGroup `
--name $VmName `
--command-id RunPowerShellScript `
--scripts "ufw disable"

Note: The ` character is the backtick. The one on the same key as the tilde ~

The same command without line continuation backticks works:

az vm run-command invoke --resource-group Development --name ubuntu-test --command-id RunShellScript --scripts "ufw disable"

If I do a Write-Host the output is a single line with the correct arguments minus the quotes around the --script command.

Write-Host az vm run-command invoke `
--resource-group $ResourceGroup `
--name $VmName `
--command-id RunPowerShellScript `
--scripts "ufw disable"

az vm run-command invoke --resource-group Development --name ubuntu-test --command-id RunPowerShellScript --scripts ufw disable

The documentation for the AZ CLI invoke command mentions nothing about setting the OS Type.

az VM run-command invoke

John Hanley
  • 74,467
  • 6
  • 95
  • 159

1 Answers1

2

I think the use of line-continuations (` at the very end of lines) is incidental to your problem.

Apart from the use of variables vs. literals, the crucial difference between your multi-line command and your working single-line command is:
--command-id RunPowerShellScript vs. --command-id RunShellScript
.

It looks like the VM you're targeting is a Linux machine, and that --command-id RunPowerShellScript isn't supported there, whereas --command-id RunShellScript is.

az vm run-command list ... can apparently be used to discover supported --command-id values.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Thank you. This is an example of **not seeing** a problem right in front of me. Even in my question is used two different forms **RunShellScript** and **RunPowerShellScript**. Your second eyes solved my problem. Now I also know why the error message said Windows. I knew that PowerShell run commands are not supported on Linux. – John Hanley Sep 19 '21 at 01:25