Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Open PowerShell ISE as an administrator.

  2. 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 –CompressionLevel Optimal -DestinationPath...