Given the code below, how do I set a variable that I can use to call the 7z executable? The env:Path approach at the top works once but then the terminal must be reloaded or the command cannot be found. Powershell seems to be treating it as a string, not as an executable call. Ultimately, I need to be able to pull this value in from the environment.
# $env:Path += "C:\Program Files\7-Zip"
# works once, then the terminal must be reloaded
$7zip = "C:\Program Files\7-Zip\7z.exe"
$dirAsStr = "C:\Program Files\7-Zip\7z.exe"
$dirAsDir = Get-Item $dirAsStr
$extract_files = "somewhere"
$output = "someplace"
# $dirAsDir a -t7z $output\format_files.7z $extract_files\format.*
# ParserError: Unexpected token 'a' in expression or statement.
# $7zip a -t7z $output\format_files.7z $extract_files\format.*
# ParserError: Unexpected token 'a' in expression or statement.
C:\"Program Files"\7-Zip\7z.exe a -t7z $output\format_files.7z $extract_files\format.*
# works fine
&. Thanks!