title: Creating .bat file with e-mail body in Powershell
body: <p>I'm currently working on a script which will read a mail from a certain sender, who will be sending some commands for the scripts to run. </p>
  
  <h2>The Main Idea:</h2>
  
  <p>Sender sends a mail with a command for example: <code>ipconfig /all &gt; result.txt</code> and the script running at the recipients side copies this command to a .bat file and running the .bat file to process the command.</p>
  
  <h2>The Code:</h2>
  
  <pre><code>$junk = $routlook.GetDefaultFolder(23)
  $MI = $junk.items
  
  foreach($m in $MI)
  {
      if($m.SenderEmailAddress -eq '&lt;sender-address&gt;')
      {
          Echo "@ECHO OFF" &gt; com.bat
          Echo $MI.item(1).Body &gt; com.bat
          .\com.bat
      }
      break
  }
  </code></pre>
  
  <h2>The Error:</h2>
  
  <p><a href="https://i.stack.imgur.com/IwFTT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IwFTT.png" alt="enter image description here"></a></p>