title: Defaults for null values
body: <p>Working on a Powershell script I had several places where I wanted A unless it was null, else B.  Essentially the ?? operator in C#.  I ended up writing the function shown below, but I can't help but think there is a built-in way to do this.</p>
  
  <p>Is there a better, built-in, way?</p>
  
  <pre><code>function Get-ValueOrDefault()
  {
      foreach ($value in $args)
      {
          if ($value -ne $null) { return $value }
      }
  }
  </code></pre>
  
  <p>I think this works better:</p>
  
  <pre><code>function Get-ValueOrDefault() { $args | select -first 1 }
  </code></pre>