title: How to put a single PowerShell output string into a cmd variable?
body: <p>I have a PowerShell script that outputs a single string value.  I have a cmd batch script that needs to execute the PowerShell script and place that single PowerShell output value into a variable in the batch script.  I'm finding all sorts of methods for exporting to a file or reading a file but that's not what I want.  Thanks!</p>
  
  <p>(edit) Here's where I'm trying to use it (in response to posting the script):</p>
  
  <pre><code>@echo off
  REM The next line puts the .ps1 output into the variable
  REM and, obviously, this does not work
  set pass_word=&lt;C:\temp\PullPassword.ps1
  tabcmd login -s "http://myserver.net" -u mylogon -p %pass_word%
  </code></pre>
  
  <p>( edit )
  I saw the answer by the OP here <strong><a href="https://stackoverflow.com/questions/20367247/getting-powershell-variable-value-in-batch-scipt?rq=1">Getting Powershell variable value in batch script</a></strong> and also looked at foxdrive's answer so I started playing with the FOR...DO statement.  I thought I was pretty good with cmd and couldn't figure out why what I had wasn't working:</p>
  
  <pre><code>for /f "delims=" %%a in ('powershell . "C:\temp\PullPassword.ps1"') do set val=%%a
  echo  %a% 
  </code></pre>
  
  <p>When I was looking at foxdrive's full answer in the other post it struck me: %a% was wrong, I needed %val%!  Oh, the shame!  The below works:</p>
  
  <pre><code>@echo off
  set mypath=C:\temp\PullPassword.ps1
  for /f "delims=" %%a in ('powershell . "C:\temp\PullPassword.ps1"') do set pass_word=%%a 
  tabcmd login -s "http://myserver.net" -u mylogon -p %pass_word%
  </code></pre>
  
  <p>So I'll credit where it's due and mark foxdrive's answer correct, even though it was the other post that <em>clarified</em> my mistake.</p>