title: How to convert parameter type into a different object type
body: <p>I'm doing some scripting in PowerShell, and I was wondering if there's a way to "declare" a parameter "X" the same way parameter "-Credential" is declared, for example in Get-WMIObject cmdlet.</p>
  
  <p>Let me be more specific. The Credential parameter in almost all cmdlets is a PSCredential Object. But, the argument can be either a PSCredential Object or, a String Object with the username.</p>
  
  <pre><code>[CmdletBinding()]
  param ([Parameter(Mandatory = $false)]
         [System.Management.Automation.PSCredential]
         $Credential)
  </code></pre>
  
  <p>The problem comes when passing a string. Of course, an argument transformation on the parameter cannot be done. Cannot convert the type "System.String" into a type PSCrendential.</p>