7-Zip and unzipping from command line
e (Extract) command
x (Extract with full paths) command
-o (set Output directory) switch
7-zip can be used in powershell for extracting .zip file. To call 7-zip simply use:
> 7z
# or
> 7z --help
To extract the files in the same folder where the .zip file is located, use the e (Extract) command
. This will not keep
the subfolders from the .zip file:
> 7z e folder.zip
# or
> 7z e 'path\to\folder.zip'
If you want to keep the files in their respective subfolders, you need to use the x (Extract with full paths) command
like this:
> 7z x folder.zip
# or
> 7z x 'path\to\folder.zip'
If you want to extract the files to a specified folder, use the -o (set Output directory) switch
. Keep in mind that
there is no space between the switch -o
and the destination folder. If that folder does not exist,
it will be created automatically:
> 7z x files.zip -ofolder
# or
> 7z x 'path\to\folder.zip' -ofolder
# You can also use e instead of x if you don't want to keep the subfolders, only the files.
How to handle command-line arguments in PowerShell
PowerShell Parameters
How do you execute an arbitrary native command from a string?
Invoke-Expression
Powershell Remove all text after last instance of \
It's not really PowerShell, it's PowerShell running a 7zip executable. I've been doing that for years. Not really what I am looking for.