title: Powershell using call operator on 7zip
body: <h1>Intro</h1>
  
  <p>So, I'm attempting to read in a zip file from a directory, and unzip that to a tmp location.  The problem is that powershell seems to be misinterpreting the quotes and not writing out the value of the $copyLocation variable.  Instead, it is copying the files to [currentDirectory]\$copyLocation.  I'm hoping you all can help.  I'm new to Powershell, and this is only a piece of the script I have to write to take over our build automation.  Thank you in advance.</p>
  
  <p>By the way, hosts is an XmlElement which we are iterating over.  So, we're deploying this zip file to a location on a number of hosts specified in an xml configuration file.</p>
  
  <pre><code>function copyWebappToDestination($copyWebappFrom,$to,$hosts){
  foreach( $it in $hosts ){
      Write-Host "Deploying webapp" $webapps.webappName "to" $it.hostIp "at" $it.to
  
      setUpDirectories
  
      foreach($file in $filelocation){
          if($file.name.ToString() -eq "Web.Main.zip"){
              $filename = $file.name.ToString()
              $hostIp = $it.hostIp
              $fileDest = $file.FullName
              #unzip the files
              &amp; '7z' x ""$fileDest"" -o""$copyLocation"" -y -r
              break
          }
      }
  }
  </code></pre>
  
  <h1>Edit</h1>
  
  <p>The weirdest part, is that I wrote out the command</p>
  
  <pre><code>&amp; '7z' x "C:\MoveToProduction\SM\PROD\Web.Main.zip" -o"C:\MoveToProduction\SM\PROD\tmp" -y -r"
  </code></pre>
  
  <p>And ran that from a Powershell console, and it worked just fine.  It just doesn't work from within the context of a script.</p>
  
  <h1>Edit Final</h1>
  
  <p>So, I gave up trying to get the call operator working.  Basically, what I ended up settling on was the command:</p>
  
  <pre><code>Invoke-Expression -command  "cmd /C '7z x `"$fileDest`" -o`"$copyLocation`" -y -r'"
  </code></pre>