How to Zip and UnZip files using PowerShell
Today we are going to Learn all about Compressing and Decompressing a file using Powershell. So lets get started.
Powershell 5.0 have lots of features added to its feather. One of them is Zipping and Unzipping . Powershell 5.0 contains 2 functions by default for Zipping and Unzipping a file i.e. Compress-Archive and Expand-Archive
Zip : Compress-Archive -path <Source_File_Path> -DestinationPath <Destination_File>
Unzip : Expand-Archive -path <Zip_file_path_to_Extract> -DestinationPath <Destination_path_where_to_Extract>
>_ If you are using Powershell version below 5.0 then you can achieve the same by Calling a Class.
ZIP - FILE
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory("E:\The Powershell Geek", "E:\sample.zip")
Add-Type -Assembly "System.IO.Compression.FileSystem"
Hope you all liked it.. Keep Learning and do share. If you have any queries related to Powershell then do comment we will take it up in our next post.