title: save FTP request to string --> Invoke-Expression to DOS
body: <p>I want to send a FTP request from PowerShell, through the DOS command line, without pointing it to a saved script.</p>
  
  <p>I have tried doing this by running the following script, but I am getting the following error:</p>
  
  <blockquote>
    <p>Invoke-Expression : Missing '(' after 'if' in if statement. At line:18
    char:18
    + Invoke-Expression &lt;&lt;&lt;&lt;  "cmd.exe /c $cmd"
        + CategoryInfo          : ParserError: (OpenParenToken:TokenId) [Invoke-Expression], ParseException
        + FullyQualifiedErrorId : MissingEndParenthesisInIfStatement,Microsoft.PowerShell.Commands.InvokeExpressionCommand</p>
  </blockquote>
  
  <p>my code is below:</p>
  
  <pre><code>$cmd = '@echo off setlocal set uname=user
      set passw=pass
      set hostname=host
      set filespec=spec
  echo %uname%&gt;                     test.ftp 
  echo %passw%&gt;&gt;                    test.ftp 
  echo pwd&gt;&gt;                        test.ftp 
  echo cd DIR&gt;&gt;                     test.ftp 
  echo binary&gt;&gt;                     test.ftp 
  echo get %filespec%&gt;&gt;             test.ftp 
  echo bye&gt;&gt;                        test.ftp 
  ftp -s:test.ftp %hostname% 
  if errorlevel 1 pause 
  endlocal 
  ' 
  Invoke-Expression "cmd.exe /c $cmd"
  </code></pre>
  
  <p>How can I change this script to make it work? I already tried using <code>FtpWebRequest</code> and <code>WebClient</code> and was not able to get it to work. Please reply with suggestions about how to implement the <code>save FTP request to string --&gt; Invoke Expression</code> approach.</p>