title: Powershell output to a text file
body: <p>I am creating a script that pulls all of the date and time information from our servers. The script gets the servers from a text file. I am having is getting the output of a script to be written to a text file. </p>
  
  <p>I tried using a pipe with Out-File like so:</p>
  
  <pre><code>$servers = gc "C:\Users\Public\Shell_NTP\TestList.txt"
  
  foreach ($server in $servers){
  $dt = gwmi win32_operatingsystem -computer $server
  $dt_str = $dt.converttodatetime($dt.localdatetime)
  write-host "$($server) current local time is $($dt_str)" | Out-File 
  "C:\Users\Public\Shell_NTP\TestListOutput.txt"
  </code></pre>
  
  <p>Then I tried the simple carrot output like so:</p>
  
  <pre><code>$servers = gc "C:\Users\Public\Shell_NTP\TestList.txt"
  
  foreach ($server in $servers){
  $dt = gwmi win32_operatingsystem -computer $server
  $dt_str = $dt.converttodatetime($dt.localdatetime)
  write-host "$($server) current local time is $($dt_str)" &gt; 
  C:\Users\Public\Shell_NTP\TestListOutput.txt
  </code></pre>
  
  <p>And that did not work either. So any help or advice would be excellent.</p>
  
  <p>TL;DR Trying to get the powershell output into a text file or some other more usable file format.</p>