title: Enter password with masking
body: <p>I have a simple example pieced together from some other posts:</p>
  
  <pre><code>[CmdletBinding(
      DefaultParameterSetName = 'Secret'
  )]
  Param (
      [Parameter(Mandatory=$True)]
      [string]$FileLocation,
  
      [Parameter(
          Mandatory = $True,
          ParameterSetName = 'Secret'
      )]
      [Security.SecureString]${Type your secret password},
      [Parameter(
          Mandatory = $True,
          ParameterSetName = 'Plain'
      )]
      [string]$Password
  )
  
  if ($Password) {
      $SecretPassword = $Password | ConvertTo-SecureString -AsPlainText -Force
  } else {
      $SecretPassword = ${Type your secret password}
  }
  
  Write-Host $SecretPassword
  $BSTR = `
      [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecretPassword)
      $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
      Write-Host $PlainPassword
  </code></pre>
  
  <p><a href="https://social.technet.microsoft.com/wiki/contents/articles/4546.working-with-passwords-secure-strings-and-credentials-in-windows-powershell.aspx" rel="nofollow noreferrer">https://social.technet.microsoft.com/wiki/contents/articles/4546.working-with-passwords-secure-strings-and-credentials-in-windows-powershell.aspx</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15007104/how-can-i-use-powershells-read-host-function-to-accept-a-password-for-an-extern">How can I use powershell&#39;s read-host function to accept a password for an external service?</a></p>
  
  <p>When running the script how can I make it possible for the entered password to be masked?</p>
  
  <p>So instead of this:</p>
  
  <pre><code>PS C:\temp&gt; .\test.ps1 -FileLocation C:\Temp\file.csv  -Password secret
  </code></pre>
  
  <p>This</p>
  
  <pre><code>PS C:\temp&gt; .\test.ps1 -FileLocation C:\Temp\file.csv  -Password ******
  </code></pre>