3

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.