Unzipping a file on your PowerShell command line may come in handy sometimes, when the winzip or default compression is not working. All that is required is PowerShell and the .NET 4.5 Framework.
A simple way of using ExtractToDirectory
from System.IO.Compression.ZipFile
:
Add-Type -AssemblyName System.IO.Compression.FileSystem
function unzip {
param( [string]$ziparchive, [string]$extractpath )
[System.IO.Compression.ZipFile]::ExtractToDirectory( $ziparchive, $extractpath )
}
unzip "D:\file.zip" "C:\temp"
in PowerShell 5.0, there is an Expand-Archive
command built in:
Expand-Archive D:\file.zip -DestinationPath C:\temp
To compress, you can use Compress-Archive
.
Use the automatic $PSVersionTable
variable, and check the PSVersion
property, to get the PowerShell version. For example: $PSVersionTable.PSVersion
P
Facebook Comments