title: Powershell store pipeline return value to variable
body: <p>I have a PowerShell function which reads the status of my SQL agent job.</p>
  <pre><code>function get-SQLJobStatus
  {
      param(
          [string]$server, 
          [string]$jobName
      )
  
      [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
  
      $srv = New-Object Microsoft.SqlServer.Management.SMO.Server($server)
      if($jobName)
      {
          $srv.JobServer.Jobs | where {$_.Name -match $jobName} | Select CurrentRunStatus
      }
  }
  </code></pre>
  <p>If I run this function, the return looks like below</p>
  <pre><code>CurrentRunStatus
  ________________
  Idle
  </code></pre>
  <p>What I want to do is run this <code>get-SQLJobStatus</code> function and check if <code>CurrentRunStatus == Idle</code>. It seems like I can't just store those return into the variable so I am stuck.</p>
  <p>Any idea?</p>