PS C:\PowerShell> Compress-Archive -Path ".\SampleFile.txt" -DestinationPath ".\SampleFile-Fastest.zip" -CompressionLevel "Fastest" And observe that, the processing time is more (depends on the file size) when we select the “ Optimal” compression level. On the other hand, “ Optimal” compression level will be used to compress the files or directories using available optimal compression methods which can result in smaller file sizes. This command will use the fastest compression method available to compress the selected files or folders/directories and observe that you will not see a big difference in the file sizes. Usually, we select the “ Fastest” compression level, to reduce the processing time. By default, this command considers the compression level value, “ Optimal” to compress the specified files or directories. And we must enclose these values in double quotes (for example “ Fastest“). Through this parameter, we can pass the values Fastest, NoCompression, or Optimal. PS C:\PowerShell> Compress-Archive -Path "C:\Movies\*" -DestinationPath "C:\Archive\AllMovies.zip"Ĭompress-Archive cmdlet provides flexibility to us to select the level of compression to apply on the selected files or folders/directories through its -CompressionLevel parameter. PS C:\PowerShell> Compress-Archive -Path "C:\Photos\*.*" -DestinationPath ".\OnlyFewPhotos.zip" When we use “*.*”, it only archives the files within the specified directory, not in it’s sub-directories.įor example, below commands archives all the files in the specified directory, and archives the files in the specified directory & it’s sub-directories respectively. When we use “*” wildcard, the Compress-Archive cmdlet archives all the files and sub-directories with in the specified directory. We can also use wildcards in the -Path argument. PS C:\PowerShell> Compress-Archive -Path ".\SampleFile.txt" -DestinationPath ".\SampleFile.zip" Below is an example, to archive the specified file. We can use absolute or relative paths in this parameter to specify where to store the archived files. + FullyQualifiedErrorId : ParameterArgumentTransformationError,Compress-Archive + CategoryInfo : InvalidData: (:), ParameterBindingArgumentTransformationException If we pass multiple paths through this parameter, this command will throw the below error. This parameter doesn’t allow multiple paths. Where to store the archived files or directories? We can specify the location where to store the zipped files or directories through the command’s -DestinationPath parameter. We can specify the absolute or relative paths to the files or directories through this parameter.Īnd always it is a good idea to keep the file or directory paths in double quotes when you pass them through the commands’ arguments. If multiple files or directories are specified, we need to separate them using a comma (,) symbol. We can specify the list of files or directories to be archived through its -Path argument. PowerShell provides Compress-Archive cmdlet, to archive the specified files or directories. Compress-Archive cmdlet – Compress / Zip / Archive the selected files or directories Through this article, we are going to discuss the PowerShell command to zip the selected files or directories. Windows PowerShell provides commands to zip (compress) and unzip the files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |