title: Powershell Function Not Working With Return
body: <pre><code>   function Get-CHPEL-Report
          {
              Clear-Host
              Write-Output &quot;Finding Newest CHPEL Report&quot;
              $PathCHPEL = Get-ChildItem -Path S:\CHPEL | Sort-Object LastWriteTime | Select-Object -last 1 | Select-Object FullName | ForEach-Object{$_.FullName}
              Write-Output &quot;Loading - $PathCHPEL&quot;
              #$global:CHPEL = Get-Content -Path $PathCHPEL | Select-Object -Skip 1 | ConvertFrom-Csv -Delimiter &quot;`t&quot;
              $CHPEL = Get-Content -Path $PathCHPEL | Select-Object -Skip 1 | ConvertFrom-Csv -Delimiter &quot;`t&quot;
              return $CHPEL
              Clear-Host
          }
          
      $CHPEL = Get-CHPEL-Report
  </code></pre>
  <p>If i run this code I don't get anything written out to the screen and $CHPEL is empty.
  But the code does work if I make the variable global in the function and just call the function. How can I make this work with Return so I don't have to have a global variable?</p>
  <pre><code>   function Get-CHPEL-Report
          {
              Clear-Host
              Write-Output &quot;Finding Newest CHPEL Report&quot;
              $PathCHPEL = Get-ChildItem -Path S:\CHPEL | Sort-Object LastWriteTime | Select-Object -last 1 | Select-Object FullName | ForEach-Object{$_.FullName}
              Write-Output &quot;Loading - $PathCHPEL&quot;
              $global:CHPEL = Get-Content -Path $PathCHPEL | Select-Object -Skip 1 | ConvertFrom-Csv -Delimiter &quot;`t&quot;
              Clear-Host
          }
  
  Get-CHPEL-Report
  </code></pre>