title: Powershell - Output directory recurse to console and file
body: <p>I'm outputting share folder structures to a text file using the code below:</p>
  
  <pre><code>$path = "\\server\share"
  $file = "c:\share-folders.txt"
  get-childitem "$path" -recurse -directory | select -expand fullname &gt;&gt; "$file"
  </code></pre>
  
  <p>I would also like to write it to the console at the same time as a way of tracking status.  I've tried using tee-object to append the file and then pipe to write-host, but at best I have only been able to output to the text file, or to the console, but not both at once.  Does anyone know the proper method to accomplish this?</p>
  
  <hr>
  
  <p><strong>Solution:</strong> Adding -Append to the end of the Tee-Object cmdlet resolved the issue.</p>
  
  <pre><code>$path = "\\server\share"
  $file = "c:\share-folders.txt"
  Get-ChildItem "$Path" -Recurse -Directory | Select -Expand FullName | Tee-Object -FilePath "$File" -Append
  </code></pre>