title: Powershell Access Azure DevOps Secret Variables
body: <p>I am attempting to read an Azure DevOps secret variable from a Powershell pipeline script. The variable looks like this within Azure:</p>
  
  <p><a href="https://i.stack.imgur.com/7m39S.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7m39S.png" alt="enter image description here"></a></p>
  
  <p>I've attempted to access the secret variable both as a <code>param</code> such as </p>
  
  <pre><code>[CmdletBinding()]
  Param (
      $SecurePassword = $env:Password
  )
  </code></pre>
  
  <p>and simply as an environment variable such as </p>
  
  <pre><code>$SecurePassword = $env:Password
  </code></pre>
  
  <p>Unfortunately the variable continues to appear null using either method.</p>
  
  <p><a href="https://i.stack.imgur.com/lnmbm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lnmbm.png" alt="enter image description here"></a></p>
  
  <p>I have no issue accessing <em>non-secret</em> variables. Any help would be greatly appreciated. </p>
  
  <p>---------------------------------------- <strong>EDIT</strong> ----------------------------------------</p>
  
  <p>I found documentation <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&amp;tabs=classic%2Cbatch#secret-variables" rel="noreferrer">here</a> stating that secrets are available to scripts within the pipeline if explicitly mapped in the environment section of the task. </p>
  
  <p><a href="https://i.stack.imgur.com/vkLFB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vkLFB.png" alt="enter image description here"></a></p>
  
  <p>I've updated my Powershell task and attempted to map the variable as both <code>$(Password)</code> and <code>Password</code> without any luck. </p>
  
  <p><a href="https://i.stack.imgur.com/ZgaR5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZgaR5.png" alt="enter image description here"></a></p>
  
  <p>Mapping <code>$(Password)</code> as above reveals the string hidden behind asterisks. </p>
  
  <p><a href="https://i.stack.imgur.com/8FYKk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8FYKk.png" alt="Using $(Password) returns"></a></p>