In the past it was not possible to create Zip files and Unzip archives in Windows without installing third-party programs like WinZip and 7-Zip.
But now Windows has a built-in capability to Zip files and folders and Unzip archives from the command line using PowerShell.
Starting from Windows 8 with PowerShell 3.0 and .NET Framework 4.5 installed by default, it is possible to use a kind of zip
and unzip
commands from the command line.
Cool Tip: Download a file using PowerShell! Read more →
Zip/Unzip From The Command Line In Windows
Depending on the version of PowerShell there are different ways to Zip files and folders and Unzip archives in Windows from the command line.
To determine a version of PowerShell on your machine, execute:
PS C:\> $PSVersionTable.PSVersion
PowerShell 5.0 (Windows 10) and greater
Starting from PowerShell 5.0 (Windows 10), it is possible to Zip files and folders and Unzip archives in Windows using Compress-Archive and Expand-Archive PowerShell commands.
Zip a file or a folder from the command line in Windows:
PS C:\> Compress-Archive -Path 'C:\input' -DestinationPath 'C:\output.zip'
Zip all files in a folder:
PS C:\> Compress-Archive -Path 'C:\folder\*' -DestinationPath 'C:\output.zip'
Unzip an archive from the command line in Windows:
PS C:\> Expand-Archive -Path 'C:\input.zip' -DestinationPath 'C:\output'
PowerShell 3.0 (Windows 8) and greater
Starting from PowerShell 3.0 (Windows 8), it is possible to Zip folders and Unzip archives in Windows from the command line using the special methods in PowerShell.
Zip all files in a folder from the command line in Windows:
PS C:\> Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('C:\folder', 'C:\output.zip')
Unzip an archive from the command line in Windows:
PS C:\> Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('C:\input.zip', 'C:\output')
that’s helpful!
Global auto-save to my wallet
What I don’t get is that the zip and unzip commands are not build into Powershell or cmd. This is very bad.
The tipp is great, but – sorry to say – it is horrible that Windows doesn’t provide an EASY way to zip and unzip.
Unzip an archive from the command line in Windows:
Error
+ Expand-Archive -Path ‘D:\zabbix4_autoinstall_win.zip ‘ -DestinationPa …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (.zip :String) [Expand-Archive],IOException
+ FullyQualifiedErrorId : NotSupportedArchiveFileExtension,Expand-Archive