Let’s say you have an Azure Automation Runbook, which has a PowerShell Switch type parameter. Now when you execute this Runbook or schedule it for a frequency-based execution, you may need to provide values for one or more Parameters defined for the Runbook. What will you provide as the value for the Switch type parameter?
You cannot pass usual values depicting true/false results viz. $true, $True, $false, $False, 1, 0, 1.0 and the likes because you will get an error as shown below.
When faced with this problem, I searched everywhere on the Web and found literally nothing workable. This Information was unclear even on the most authoritative blog post on the Innards of Azure Automation published by Chris Sanders in August 2014 here: Azure Automation: Runbook Input, Output, and Nested Runbooks
Almost all other links where this particular problem was referenced, only alternative best-practices advice on using a PowerShell bool type was advocated to be used instead of Switch type for the parameter, rather than clearly tell what should be passed as value for the Switch parameter if we were absolutely adamant to keep the same.
I then discovered on my own (the hard way) that we need to simply provide the values true or false (Is case sensitive – won’t work with True or False) without any decorations like double quotes, single quotes, square brackets, parentheses, braces, JSON format string etc..
You can see the successful execution of a sample Azure Automation Runbook with a single Switch type parameter named $DefaultBase in the screenshot below. Look at the true value I passed for the Switch type parameter and the sample Output.
Similarly, see the screenshot when I pass the value false for the Switch type parameter.
Hope you found this blog post useful. If you have any queries/feedback, please feel free to mention in the comments section below.