Using the PowerShell call (&) operator to call PowerShell scripts with switch parameters
<p>Suppose we have the following <code>SwitchTest.ps</code> script</p>

<pre><code>param(
    [switch]$Flag = $false
)

echo "Flag: $Flag"
</code></pre>

<p>The following works as expected:</p>

<pre><code>&amp; ".\SwitchTest.ps1" -Flag
Flag: True
</code></pre>

<p>However this doesn't</p>

<pre><code>&amp; ".\SwitchTest.ps1" "-Flag"
Flag: False
</code></pre>

<p>Furthermore, if we modify <code>SwitchTest.ps</code> to look like this:</p>

<pre><code>param(
    [switch]$Flag = $false,
    [string]$Str = $null
)

echo "Flag: $Flag"
echo "Str: $Str"
</code></pre>

<p>We get this expected behavior:</p>

<pre><code>&amp; ".\SwitchTest.ps1" -Flag
Flag: True
Str: 
</code></pre>

<p>And this unexpected one:</p>

<pre><code>&amp; ".\SwitchTest.ps1" "-Flag"
Flag: False
Str: -Flag
</code></pre>

<p>I tried <code>-Flag true</code>, <code>-Flag $true</code>, <code>-Flag:$true</code>... no cigar. It looks like the switch param is "skipped" when quoted (i.e. when it's a proper string) - why? What do I do if I want to build <code>"-Flag"</code> programmatically?</p>