title: Running 7-Zip from within a Powershell script
body: <p>I'm trying to use 7-Zip to backup some files inside a Powershell (v2) script.</p>
  
  <p>I have:</p>
  
  <pre><code>$zipPath = "C:\Program Files\7-Zip\7z.exe"
  [Array]$zipArgs = "-mx=9 a", "`"c:\BackupFolder\backup.zip`"", "`"c:\BackupFrom\backMeUp.txt`""
  
  &amp;$zipPath $zipArgs;
  </code></pre>
  
  <p>But when I run this I get:</p>
  
  <pre><code>7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
  
  
  Error:
  Incorrect command line
  </code></pre>
  
  <p>Writing this to the screen I get:    </p>
  
  <pre><code>C:\Program Files\7-Zip\7z.exe -mx=9 a "c:\BackupFolder\backup.zip" "c:\BackupFrom\backMeUp.txt"
  </code></pre>
  
  <p>So I assumed that I needed to put quotes around the path to 7z.exe, that gave me:</p>
  
  <pre><code>$zipPath = "C:\Program Files\7-Zip\7z.exe"
  $zipPath = " `"$zipPath`" "
  [Array]$zipArgs = "-mx=9 a", "`"c:\BackupFolder\backup.zip`"", "`"c:\BackupFrom\backMeUp.txt`""
  
  &amp;$zipPath $zipArgs;     
  </code></pre>
  
  <p>But then I get the following error:</p>
  
  <pre><code>    The term '"C:\Program Files\7-Zip\7z.exe"' is not recognized as the name of a cmdlet, function, script file
  , or operable program. Check the spelling of the name, or if a path was included, verify that the path is c
  orrect and try again.
  At C:\BackupScript\Backup.ps1:45 char:22
  +                     &amp; &lt;&lt;&lt;&lt; `"$zipPath`" $zipArgs;                    
      + CategoryInfo          : ObjectNotFound: ("C:\Program Files\7-Zip\7z.exe":String) [], CommandNotFound 
     Exception
      + FullyQualifiedErrorId : CommandNotFoundException
  </code></pre>
  
  <p>Writing it out gives me:</p>
  
  <pre><code>"C:\Program Files\7-Zip\7z.exe" -mx=9 a "c:\BackupFolder\backup.zip" "c:\BackupFrom\backMeUp.txt"
  </code></pre>
  
  <p>Which works as expected when pasting straight into a command window.
  I have been trying to figure this out for a while, but assume I am missing something (probably quite obvious). Can anybody see what I need to do to make this run?</p>