Search code examples
powershellcmdpowershell-2.07zip

Unable to run 7-Zip in Powershell


This came up in a discussion on another question I asked on running executables in Windows Powershell

Whenever I run 7z in my workplace machine that has PS 2.0, I get this error

Bad numeric constant: 7.
At line;1 char:2
+ 7 <<<< z
    + CategoryInfo          : ParserError: <7:String> [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : BadNumericConstant.

Note that this error occurs even if I give the full filename 7z.exe. However, if I go into Command Line mode by entering cmd it works without any problems.

Any help would be appreciated.


Solution

  • Try this:

    & "Path\to\7z.exe" arg1 arg2 etc
    

    It sounds like PowerShell is trying to interpret your [String] literally as an [Int]