title: Why the ouput of wmic piped in powershell it's different? how to correct?
body: <p>I am making a batch dos code to execute commands and capture code in files, while also keeping the output on screen.</p>
  <p><strong>EDIT2: 3 apr 21, 15:36</strong>
  <em>The commands that I want execute are slow and fast and some commands can only be executed once.
  I have to execute for example commands like chkdsk, dism, sfc, wmic, dos (internal, external), powershell.</em></p>
  <p>I thought the fastest way was to use the powershell &quot;tee&quot;.</p>
  <p>ex.
  (echo foo &amp; echo bar) | powershell &quot;$input | tee -a out.txt&quot;</p>
  <pre class="lang-PowerShell prettyprint-override"><code>C:\WINDOWS\system32&gt;(echo foo &amp; echo bar) | powershell &quot;$input | tee -a out.txt&quot;
  foo
  bar
  </code></pre>
  <p>but when i use it with wmic i have different results:</p>
  <pre class="lang-PowerShell prettyprint-override"><code>C:\WINDOWS\system32&gt;wmic recoveros get autoreboot
  AutoReboot
  FALSE
  
  
  C:\WINDOWS\system32&gt;wmic recoveros get autoreboot | powershell &quot;$input | tee -a out.txt&quot;
  AutoReboot
  
  FALSE
  
  
  
  
  C:\WINDOWS\system32&gt;
  </code></pre>
  <hr />
  <ul>
  <li>Why?</li>
  <li>Is there a way to correct without breaking the code?</li>
  </ul>
  <hr />
  <p><strong>EDIT1: 3 apr 21, 14:46</strong></p>
  <p>I add some information how suggest JosefZ:</p>
  <pre class="lang-PowerShell prettyprint-override"><code>C:\WINDOWS\system32&gt;del out.txt out2.txt
  
  C:\WINDOWS\system32&gt;wmic recoveros get autoreboot &gt; out2.txt
  
  C:\WINDOWS\system32&gt;wmic recoveros get autoreboot | powershell &quot;$input | tee -a out.txt&quot;
  AutoReboot
  
  FALSE
  
  
  
  
  C:\WINDOWS\system32&gt;type out.txt
  AutoReboot
  
  FALSE
  
  
  
  
  C:\WINDOWS\system32&gt;type out2.txt
  AutoReboot
  FALSE
  
  C:\WINDOWS\system32&gt;powershell -nopro &quot;(cat out.txt -encoding Byte) -join ' '&quot;
  255 254 65 0 117 0 116 0 111 0 82 0 101 0 98 0 111 0 111 0 116 0 32 0 32 0 13 0 10 0 13 0 10 0 70 0 65 0 76 0 83 0 69 0 32 0 32 0 32 0 32 0 32 0 32 0 32 0 13 0 10 0 13 0 10 0 13 0 10 0 13 0 10 0
  
  C:\WINDOWS\system32&gt;powershell -nopro &quot;(cat out2.txt -encoding Byte) -join ' '&quot;
  255 254 65 0 117 0 116 0 111 0 82 0 101 0 98 0 111 0 111 0 116 0 32 0 32 0 13 0 10 0 70 0 65 0 76 0 83 0 69 0 32 0 32 0 32 0 32 0 32 0 32 0 32 0 13 0 10 0
  
  C:\WINDOWS\system32&gt;
  </code></pre>
  <hr />
  <p><strong>EDIT3: 3 apr 21, 16:05</strong>
  This is the code that I developed for the moment (some commands are commented for the moment with &quot;rem&quot;):</p>
  <pre class="lang-PowerShell prettyprint-override"><code>for %%C in (
  &quot;rem sfc /scannow&quot;
  &quot;rem dism /online /cleanup-image /scanhealth&quot;
  &quot;rem dism /online /cleanup-image /restorehealth&quot;
  &quot;rem sfc /scannow&quot;
  &quot;rem&quot;
  &quot;rem chkdsk /scan&quot;
  &quot;rem&quot;
  &quot;wmic recoveros get autoreboot&quot;
  &quot;wmic recoveros set autoreboot = false&quot;
  &quot;wmic recoveros get autoreboot&quot;
  &quot;wmic recoveros get DebugInfoType&quot;
  &quot;wmic recoveros set DebugInfoType = 7&quot;
  &quot;wmic recoveros get DebugInfoType&quot;
  &quot;rem&quot;
  &quot;wmic pagefile list /format:list&quot;
  &quot;wmic Computersystem where name=&quot;%COMPUTERNAME%&quot; get AutomaticManagedPagefile&quot;
  &quot;wmic Computersystem where name=&quot;%COMPUTERNAME%&quot; set AutomaticManagedPagefile=True&quot;
  &quot;wmic Computersystem where name=&quot;%COMPUTERNAME%&quot; get AutomaticManagedPagefile&quot;
  &quot;rem&quot;
  &quot;bcdedit /enum {badmemory}&quot;
  ) do ( %ComSpec% /c &quot;echo(%CD%^&gt;%%~C &amp; %%~C &quot; | powershell -command &quot; $input | tee -Append test.txt &quot;)
  </code></pre>
  <hr />
  <p><strong>EDIT4: 10 apr 2021, 8:21</strong>
  I add this code to create a reference output to facilitate the comparison process between the various tests. This output is to be considered both on screen and on file.</p>
  <pre class="lang-PowerShell prettyprint-override"><code>@echo off
  
  rem Warning! Run as administrator. 
  
  rem go safe place for testing...
  cd %temp%
  
  for %%C in (
  &quot;rem sfc /scannow&quot;
  &quot;rem dism /online /cleanup-image /scanhealth&quot;
  &quot;rem dism /online /cleanup-image /restorehealth&quot;
  &quot;rem sfc /scannow&quot;
  
  &quot;rem chkdsk /scan&quot;
  
  &quot;wmic recoveros get autoreboot&quot;
  &quot;wmic recoveros set autoreboot = false&quot;
  &quot;wmic recoveros get autoreboot&quot;
  &quot;wmic recoveros get DebugInfoType&quot;
  &quot;wmic recoveros set DebugInfoType = 7&quot;
  &quot;wmic recoveros get DebugInfoType&quot;
  
  &quot;wmic pagefile list /format:list&quot;
  &quot;wmic Computersystem where name=&quot;%COMPUTERNAME%&quot; get AutomaticManagedPagefile&quot;
  &quot;wmic Computersystem where name=&quot;%COMPUTERNAME%&quot; set AutomaticManagedPagefile=True&quot;
  &quot;wmic Computersystem where name=&quot;%COMPUTERNAME%&quot; get AutomaticManagedPagefile&quot;
  
  &quot;bcdedit /enum {badmemory}&quot;
  
  ) do ( 
         rem Partially simulates &quot;echo on&quot; on commands. 
         echo(%CD%^&gt;%%~C
         rem Execute command.
         %%~C
         rem alternative, but opens another cmd process. 
         rem %ComSpec% /c &quot;echo(%CD%^&gt;%%~C &amp; %%~C&quot;
  )
  
  pause
  
  goto :eof
  </code></pre>
  <hr />