2

I've been using Azure CLI to execute powershell scripts inside a vm, even using string parameters. But when the scripts contains a boolean parameter to add, the azure invoke command doesn't pass it to to the script execution. Anyone has succeded to find the correct syntax to pass boolean type parameters with Azure CLI Invoke RunPowerShellScript?

I have tried the following combinations but didn't work:

az vm run-command invoke -g <resource group> -n <vm name> --command-id RunPowerShellScript --scripts "@....\Desktop\write-host.ps1"...

--parameters boolean1=$true
--parameters boolean1=True
--parameters "-boolean1 $True"
--parameters "-boolean1 True"
--parameters "boolean1 $True"
--parameters "boolean1 True"

The microsoft documentation doesn't have any information related to passing boolean parameters.

I've put the same question in here that could provide some context to my problem.

  • If Azure calls _Windows PowerShell_ (as opposed to PowerShell [Core] v6+) and does so via the PowerShell CLI's `-File` parameter, then you won't be able to pass Booleans. Taking a step back: instead of defining Boolean parameters, scripts should use `[switch]` parameters, where, on invocation, their _absence_ implies `$false`, and their _presence_ `$true`. – mklement0 Jun 30 '20 at 02:52
  • I've tried also the [switch] parameter by passing it like this: `... --parameters -param1` and `--parameters param1:true `as you usually do in powershell but didn't work. I think the az vm run-command is restricted just to string parameters at the moment. – Sergio Quintero Restrepo Jun 30 '20 at 13:56
  • `-param1:true` can't be expected to work in Windows PowerShell (it works in PowerShell Core); however, `-param1` - which _implies_ `$true` should work in both editions, assuming that `-File` is used behind the scenes. – mklement0 Jun 30 '20 at 18:58

0 Answers0