title: Check whether a variable is null
body: <p>I'd like to check if a variable is null:</p>
  
  <pre><code>function send_null_param ([ref]$mycredentials){
    if (! $mycredentials) {
      Write-Host 'Got no credentials'
      $mycredentials = Get-Credential 'mydomain.com\myuserid' 
    } else {
      Write-Host 'Got credentials'
    }
  }
  
  $myidentifier = $null
  
  send_null_param ([ref]$myidentifier)
  </code></pre>
  
  <p>This code is based on:
  <a href="https://www.thomasmaurer.ch/2010/07/powershell-check-variable-for-null/" rel="nofollow noreferrer">https://www.thomasmaurer.ch/2010/07/powershell-check-variable-for-null/</a>,
  but this does not work.</p>
  
  <p>How can I fix this?</p>
  
  <p>ps. There is something in Stack&nbsp;Overflow for a string being null but not something more generic:
  <a href="https://stackoverflow.com/questions/45008016/check-if-a-string-is-not-null-or-empty">Check if a string is not NULL or EMPTY</a></p>