title: Why this code passing switch parameters to a PowerShell function fails
body: <p>This question is about passing switch parameters. Let's see the code. I have this PowerShell 3.0 function:</p>
  
  <pre><code>#test1.ps1
  param(
      [switch] $param1 = $false
  )
  
  Write-Host "param1: $($param1.IsPresent)"
  Write-Host
  </code></pre>
  
  <p>I have this main PowerShell function that invokes test.ps1 in four different ways:</p>
  
  <pre><code>#Test0.ps1
  cls
  
  $param1 = $True
  
  # 1
  .\test1.ps1 -param1
  
  # 2
  .\test1.ps1 -param1:$true
  
  # 3
  $potato = "-param1:`$$($param1)"
  Write-Host "Parameter value: $potato" 
  .\test1.ps1 $potato
  
  # 4
  $command = ".\test1.ps1 -param1:`$$($param1)"
  Write-Host "Command: $command" 
  iex $command
  
  exit
  </code></pre>
  
  <p><strong>Why is the 3rd way of doing it failing?</strong> I know I can do 4th way but I would love to understand why 3rd is failing.</p>
  
  <p>Here is the output. As result all the parameters should be True <strong>but third one is False</strong>...</p>
  
  <pre><code>param1: True
  
  param1: True
  
  Parameter value: -param1:$True
  param1: False
  
  Command: .\test1.ps1 -param1:$True
  param1: True
  </code></pre>