How to properly set path in Powershell and 7zip?

让人想犯罪 __ 提交于 2019-12-11 14:02:56

问题


I have a Powershell script to create a self-extracting archive via 7zip. But it's receiving this error:

cannot find specified SFX module

The Powershell code is:

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe
sz a -t7z -sfx -ppassword $fullpath $filetostore

Both variables are valid. I've tried -sfx and -sfx7z.sfx, same error. The 7z.sfx file is indeed in the correct folder with 7zip. I can also verify the alias is working, as the 7zip copyright appears when running the code (so 7zip commandline is being initiated). This command works outside Powershell.

I'm also tried Set-Location into the 7zip folder, but same error. What am I missing?


回答1:


It seems you should add the 7-zip folder to your PATH environment variable to make things easier :

#find the 7-zip folder path
$7zPath = (Get-ChildItem "C:\Program Files","C:\Program Files (x86)" -Include "7-zip" -Recurse -ErrorAction SilentlyContinue).FullName

#add it to PATH environment variable
$env:Path += ";$7zPath;"

Then you can run 7z -sfx with no errors about the SFX module.



来源:https://stackoverflow.com/questions/34096037/how-to-properly-set-path-in-powershell-and-7zip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!