Skip to content

Commit f1a7999

Browse files
davidsmatlaksdwheeler
authored andcommitted
issue 4808 (#4833)
1 parent 966a08d commit f1a7999

File tree

4 files changed

+377
-261
lines changed

4 files changed

+377
-261
lines changed

reference/5.0/Microsoft.PowerShell.Archive/Compress-Archive.md

Lines changed: 91 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ title: Compress-Archive
1212
# Compress-Archive
1313

1414
## SYNOPSIS
15-
Creates an archive, or zipped file, from specified files and folders.
15+
Creates a compressed archive, or zipped file, from specified files and folders.
1616

1717
## SYNTAX
1818

@@ -60,55 +60,71 @@ Compress-Archive -LiteralPath <String[]> [-DestinationPath] <String> [-Compressi
6060

6161
## DESCRIPTION
6262

63-
The `Compress-Archive` cmdlet creates a zipped (or compressed) archive file from one or more
64-
specified files or folders. An archive file allows multiple files to be packaged, and optionally
65-
compressed, into a single zipped file for easier distribution and storage. An archive file can be
66-
compressed by using the compression algorithm specified by the CompressionLevel parameter.
63+
The `Compress-Archive` cmdlet creates a compressed, or zipped, archive file from one or more
64+
specified files or folders. An archive packages multiple files, with optional compression, into a
65+
single zipped file for easier distribution and storage. An archive file can be compressed by using
66+
the compression algorithm specified by the **CompressionLevel** parameter.
6767

68-
The `Compress-Archive` cmdlet relies upon the Microsoft .NET API `System.IO.Compression.ZipArchive`
69-
to compress files. Therefore, the maximum file size that is 2 GB. This is a limitation of the
70-
underlying API.
68+
The `Compress-Archive` cmdlet uses the Microsoft .NET API [System.IO.Compression.ZipArchive](/dotnet/api/system.io.compression.ziparchive)
69+
to compress files. The maximum file size is 2 GB because there's a limitation of the underlying API.
70+
71+
Some examples use splatting to reduce the line length of the code samples. For more information, see
72+
[about_Splatting](../Microsoft.PowerShell.Core/About/about_Splatting.md).
7173

7274
## EXAMPLES
7375

7476
### Example 1: Create an archive file
7577

76-
This command creates a new archive file, `Draft.zip`, by compressing two files, `Draftdoc.docx` and
78+
This example creates a new archive file, `Draft.zip`, by compressing two files, `Draftdoc.docx` and
7779
`diagram2.vsd`, specified by the **Path** parameter. The compression level specified for this
78-
operation is Optimal.
80+
operation is **Optimal**.
7981

8082
```powershell
81-
Compress-Archive -Path C:\Reference\Draftdoc.docx, C:\Reference\Images\diagram2.vsd -CompressionLevel Optimal -DestinationPath C:\Archives\Draft.Zip
83+
$compress = @{
84+
Path= "C:\Test\Reference\Draftdoc.docx", "C:\Test\Reference\Images\diagram2.vsd"
85+
CompressionLevel = "Optimal"
86+
DestinationPath = "C:\Test\Archives\Draft.Zip"
87+
}
88+
Compress-Archive @compress
8289
```
8390

84-
### Example 2: Create an archive file (using LiteralPath)
91+
### Example 2: Create an archive file using LiteralPath
8592

86-
This command creates a new archive file, `Draft.zip`, by compressing two files, `Draft doc.docx` and
87-
`Diagram [2].vsd`, specified by the **LiteralPath** parameter. The compression level specified for this
88-
operation is Optimal.
93+
This example creates a new archive file, `Draft.zip`, by compressing two files, `Draft doc.docx` and
94+
`Diagram [2].vsd`, specified by the **LiteralPath** parameter. The compression level specified for
95+
this operation is **Optimal**.
8996

9097
```powershell
91-
Compress-Archive -LiteralPath 'C:\Reference\Draft Doc.docx', 'C:\Reference\Images\Diagram [2].vsd' -CompressionLevel Optimal -DestinationPath C:\Archives\Draft.Zip
98+
$compress = @{
99+
LiteralPath= "C:\Test\Reference\Draft Doc.docx", "C:\Test\Reference\Images\Diagram [2].vsd"
100+
CompressionLevel = "Optimal"
101+
DestinationPath = "C:\Test\Archives\Draft.Zip"
102+
}
103+
Compress-Archive @compress
92104
```
93105

94106
### Example 3: Create an archive with wildcard characters
95107

96-
This command creates a new archive file, `Draft.zip`, in the `C:\Archives` folder. The new archive
97-
file contains every file in the `C:\Reference` folder, because a wildcard character was used in
98-
place of specific file names in the **Path** parameter.
108+
This example creates a new archive file, `Draft.zip`, in the `C:\Archives` folder. The new archive
109+
file contains every file, folder, and subfolder in the `C:\Reference` root folder, because an
110+
asterisk (`*`) wildcard character was used in place of specific file names in the **Path**
111+
parameter. The root folder, `Reference`, is excluded from the archive.
99112

100113
```powershell
101114
Compress-Archive -Path C:\Reference\* -CompressionLevel Fastest -DestinationPath C:\Archives\Draft
102115
```
103116

104-
Notice that the file name extension .zip was not added to the value of the **DestinationPath**
105-
parameter. PowerShell appends the .zip extension to the file name automatically. The specified
106-
compression level is **Fastest**, which might result in a larger output file, but compresses a large
107-
number of files faster.
117+
Notice that the file name extension `.zip` wasn't added to the value of the **DestinationPath**
118+
parameter. PowerShell appends the `.zip` extension to the file name automatically. The specified
119+
compression level is **Fastest**. The faster compression level will compress large numbers of files
120+
faster, but might result in a larger output file.
121+
122+
> [!NOTE]
123+
> To zip only the files in the specified root folder, use the **star-dot-star** (`*.*`) wildcard.
108124
109125
### Example 4: Update an existing archive file
110126

111-
This command updates an existing archive file, Draft.Zip, in the C:\Archives folder.
127+
This example updates an existing archive file, `Draft.Zip`, in the `C:\Archives` folder.
112128

113129
```powershell
114130
Compress-Archive -Path C:\Reference\* -Update -DestinationPath C:\Archives\Draft.Zip
@@ -120,29 +136,31 @@ C:\Reference folder, and also to add new files that have been added to `C:\Refer
120136

121137
### Example 5: Create an archive from an entire folder
122138

123-
This command creates an archive from an entire folder, C:\Reference.
139+
This example creates an archive from an entire folder, `C:\Reference`. The archive contains the root
140+
folder, `Reference`, and all its files, folders, and subfolders.
124141

125142
```powershell
126143
Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft
127144
```
128145

129-
Notice that the file name extension .zip was not added to the value of the **DestinationPath**
130-
parameter. PowerShell appends the .zip extension to the file name automatically.
146+
Notice that the file name extension `.zip` wasn't added to the value of the **DestinationPath**
147+
parameter. PowerShell appends the `.zip` extension to the file name automatically.
131148

132149
## PARAMETERS
133150

134151
### -CompressionLevel
135152

136-
Specifies how much compression to apply when you are creating the archive file. Faster compression
137-
requires less time to create the file, but can result in larger file sizes. The acceptable values
138-
for this parameter are:
153+
Specifies how much compression to apply when you're creating the archive file. Faster compression
154+
requires less time to create the file, but can result in larger file sizes.
139155

140-
- **Fastest**. Use the fastest compression method available to decrease processing time; this can result
141-
in larger file sizes.
142-
- **NoCompression**. Do not compress the source files.
143-
- **Optimal**. Processing time is dependent on file size.
156+
If this parameter isn't specified, the command uses the default value, **Optimal**.
144157

145-
If this parameter is not specified, the command uses the default value, Optimal.
158+
The acceptable values for this parameter are as follows:
159+
160+
- **Fastest**. Use the fastest compression method available to reduce processing time. Faster
161+
compression can result in larger file sizes.
162+
- **NoCompression**. Doesn't compress the source files.
163+
- **Optimal**. Processing time is dependent on file size.
146164

147165
```yaml
148166
Type: String
@@ -157,12 +175,28 @@ Accept pipeline input: False
157175
Accept wildcard characters: False
158176
```
159177
178+
### -Confirm
179+
180+
Prompts you for confirmation before running the cmdlet.
181+
182+
```yaml
183+
Type: SwitchParameter
184+
Parameter Sets: (All)
185+
Aliases: cf
186+
187+
Required: False
188+
Position: Named
189+
Default value: False
190+
Accept pipeline input: False
191+
Accept wildcard characters: False
192+
```
193+
160194
### -DestinationPath
161195
162196
Specifies the path to the archive output file. This parameter is required. The specified
163-
**DestinationPath** value should include the desired name of the output zipped file; it specifies
197+
**DestinationPath** value should include the desired name of the output zipped file, and specifies
164198
either the absolute or relative path to the zipped file. If the file name specified in
165-
**DestinationPath** does not have a .zip file name extension, the cmdlet adds a .zip file name
199+
**DestinationPath** doesn't have a `.zip` file name extension, the cmdlet adds a `.zip` file name
166200
extension.
167201

168202
```yaml
@@ -196,7 +230,7 @@ Accept wildcard characters: False
196230
### -LiteralPath
197231

198232
Specifies the path or paths to the files that you want to add to the archive zipped file. Unlike the
199-
**Path** parameter, the value of **LiteralPath** is used exactly as it is typed. No characters are
233+
**Path** parameter, the value of **LiteralPath** is used exactly as it's typed. No characters are
200234
interpreted as wildcards. If the path includes escape characters, enclose each escape character in
201235
single quotation marks, to instruct PowerShell not to interpret any characters as escape sequences.
202236
To specify multiple paths, and include files in multiple locations in your output zipped file, use
@@ -221,6 +255,19 @@ parameter can accept wildcard characters. Wildcard characters allow you to add a
221255
to your zipped archive file. To specify multiple paths, and include files in multiple locations in
222256
your output zipped file, use commas to separate the paths.
223257

258+
To zip all the files, folders, and subfolders in a specified root folder, use the asterisk (`*`)
259+
wildcard. The root folder is excluded from the archive.
260+
261+
For example:
262+
263+
`-Path C:\Reference\*`
264+
265+
To zip only the files in the specified root folder, use the **star-dot-star** (`*.*`) wildcard.
266+
267+
For example:
268+
269+
`-Path C:\Reference\*.*`
270+
224271
```yaml
225272
Type: String[]
226273
Parameter Sets: Path, PathWithUpdate, PathWithForce
@@ -235,9 +282,9 @@ Accept wildcard characters: True
235282

236283
### -Update
237284

238-
Updates the specified archive by replacing older versions of files in the archive with newer
239-
versions of files that have the same names. You can also add this parameter to add files to an
240-
existing archive.
285+
Updates the specified archive by replacing older file versions in the archive with newer file
286+
versions that have the same names. You can also add this parameter to add files to an existing
287+
archive.
241288

242289
```yaml
243290
Type: SwitchParameter
@@ -251,25 +298,9 @@ Accept pipeline input: False
251298
Accept wildcard characters: False
252299
```
253300

254-
### -Confirm
255-
256-
Prompts you for confirmation before running the cmdlet.
257-
258-
```yaml
259-
Type: SwitchParameter
260-
Parameter Sets: (All)
261-
Aliases: cf
262-
263-
Required: False
264-
Position: Named
265-
Default value: False
266-
Accept pipeline input: False
267-
Accept wildcard characters: False
268-
```
269-
270301
### -WhatIf
271302

272-
Shows what would happen if the cmdlet runs. The cmdlet is not run.
303+
Shows what would happen if the cmdlet runs. The cmdlet isn't run.
273304

274305
```yaml
275306
Type: SwitchParameter
@@ -287,8 +318,7 @@ Accept wildcard characters: False
287318

288319
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
289320
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
290-
-WarningAction, and -WarningVariable. For more information, see
291-
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
321+
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
292322

293323
## INPUTS
294324

@@ -304,5 +334,4 @@ You can pipe a string that contains a path to one or more files.
304334

305335
## RELATED LINKS
306336

307-
[Expand-Archive](expand-archive.md)
308-
337+
[Expand-Archive](Expand-Archive.md)

0 commit comments

Comments
 (0)