title: Setting jenkins pipeline variable using powershell results in carriage return
body: <p>I am using a Jenkins Pipeline file for a standalone pipeline job, I am trying to find the latest folder created within a directory and assign this to a variable.</p>
  
  <p>This works perfectly, except for the fact there is a rogue carriage return in the output. I can't use <code>Write-Host -NoNewLine</code> as this will not make it's way out as a parameter.</p>
  
  <p>I have tried to replace any carriage returns on the file name, I have iterated over the ascii characters - it just seems that for some strange reason, Powershell always has this rogue "carriage return" that isn't when using <code>Write-Output</code>.</p>
  
  <pre><code>pipeline {
    agent {
      label 'orchestration'
    }
    environment {
      CLIENT_NAME = 'Test Client'
      LATEST_ORCHESTRATION_VERSION = powershell(returnStdout: true, script: '''
          Write-Output (gci D:\\Orchestration | ? { $_.PSIsContainer } | sort CreationTime)[-1].Name
      ''')
    }
    stages {
        stage('Load') {
        steps {
           bat('dotnet run "D:\Orchestration\%LATEST_ORCHESTRATION_VERSION%" -d %WORKSPACE% -c %CLIENT_NAME%')
        }
      }
    }
  }
  </code></pre>
  
  <p>Running this in Powershell works fine, but running if you do <code>Write-Output 'foo'</code> in Powershell ISE seems to replicate the carriage return (if I run the above powershell script purely in powershell it returns fine as far as I can see!)</p>
  
  <p>When I run the pipeline, the environment variable pulls through perfectly but because the carriage return seems to exist, then I get the following error in my jenkins console:</p>
  
  <pre><code>D:\workspace\Test Client&gt;dotnet run "D:\Orchestration\1.0.0.28
  
  Couldn't find a project to run. Ensure a project exists in D:\workspace\Test Client, or pass the path to the project using --project.```
  </code></pre>