title: How to write a PowerShell CmdLet that will accept a parameter of type System.Type?
body: <p>I want to pass a <code>Type</code> to a custom CmdLet, as follows:</p>
  
  <pre><code>PS&gt; "1" | My-CmdLet -Check [System.String]
  </code></pre>
  
  <p>I want to use the <code>-Check</code> parameter as the type argument for the <code>-Is</code> operator in my CmdLet:</p>
  
  <pre><code>Function My-CmdLet {
      param(
          ${Actual},
  
          [System.String]
          ${Check}           # &lt;-- I want to pass a type here
      )
  
      if (-not ($Actual -Is [Type] $Check)) {
          # ... 
      }
  }
  </code></pre>
  
  <p>When called as follows:</p>
  
  <pre><code>PS&gt; My-CmdLet 1 -Check [System.String]
  </code></pre>
  
  <p>Results in the error:</p>
  
  <pre><code>Cannot convert the "[System.String]" value of type "System.String" to type  "System.Type". At MycmdLet.ps1:19 char:9
   +     if (-not ($Actual -Is [Type] $ExpectedType)) {
   +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
   + FullyQualifiedErrorId : InvalidCastFromStringToType
  </code></pre>
  
  <p>I tried using <code>[System.String]</code>, <code>[System.Type]</code> <code>[System.Object]</code>, <code>[System.RunTimeType]</code> as the type for the <code>Check</code> parameter, but none of those seem to be working.</p>
  
  <p>For comparison:</p>
  
  <p>I can pass a type to the Where-Object cmdlet like this:</p>
  
  <pre><code>PS&gt; Get-Process | Where-Object StartTime -Is [System.Datetime]
  </code></pre>
  
  <p>(In this case the value "[System.DateTime]" gets passed on to the CmdLet parameter <code>$Value</code> which is of type <code>[System.Object]</code>)</p>
  
  <p>I can use a Type with the <code>-Is</code> operator like this:</p>
  
  <pre><code>PS&gt; "1" -Is [System.String]
  True
  </code></pre>
  
  <p><strong>How do i declare the <code>-Check</code> parameter in my CmdLet?</strong></p>