Compressing files
In this recipe, we will use the Compress-Archive
cmdlet to compress or ZIP some files.
How to do it...
The following steps walk you through compressing files using PowerShell:
- Open PowerShell ISE as an administrator.
- Add the following script and run it:
#replace the variable values with your #folder and destination file values #search for file with specific extension $folderToCompress = "C:\Temp\MyFiles" $destinationFile = $folderToCompress + ".zip" Compress-Archive -Path $folderToCompressfolderToCompress –DestinationPath $destinationFile –CompressionLevel Fastest -Update
How it works...
PowerShell V5 introduces a new cmdlet that compresses files. Compress-Archive
is an elegant way to archive or ZIP files. It accepts a folder or list of files to be zipped and the destination file. If you want to specify multiple files, you need to list them separated by a comma:
Compress-Archive -LiteralPath C:\Data\Resume.docx, C:\MyFiles\CoverLetter.pdf &...