Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

invoke expression with variable paramters - 7zip

$
0
0

I am trying to use invoke-expression to use 7zip to unzip a file.  The parameters are variable.  I seem to have a problem that stems from what I found to be the unintuitive nature of how the double and single quotes are used with invoke expression. The examples I have seen do not have variable parameters so I am not sure how the quotes should look.

Doing invoke-expression "7z.exe e -o$imagepath $filename" instead gives me a bad numeric constant error - it interprets the 7 to be a number instead of part of a command.

Please note that directory names cannot be changed.  I have simplified how $filename is set, but please assume it will normally be variable and is properly set.  Also, the path to the 7Zip executable is in my PATH environment variable (for other reasons).

The following code gives unexpected token e on the inovke-expression line:

$$toppath = "\\domainname.orgname.local\sharedir\FLR"

$imagepath = $toppath + "\Images"

$filename = $imagepath + "\FLR_03182013-03242013.zip"

 if ($filename.substring($filename.length - 3, 3) -eq "zip")
    {       
        $imagecommand = "'7z.exe' e -o$imagepath $filename"
        invoke-expression $imagecommand
    }

What should the invoke-expression look like with quotes and all?


Viewing all articles
Browse latest Browse all 8583

Trending Articles