Expand-Item

Decompresses a ZIP file to a directory using the DotNetZip library.

Syntax

Expand-Item [-Path] <String> [[-OutDirectory] <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

The contents of the ZIP file are extracted to a temporary directory, and that directory is returned as a System.IO.DirectoryInfo object. You are responsible for deleting that directory when you're finished.

You can extract to a specific directory with the OutDirectory parameter. If the directory doesn't exist, it is created. If the directory exists, and is empty, the file is decompressed into that directory. If the directory isn't empty, use the -Force parameter to overwrite any files/directories which may be present.

The directory where the files were decompressed is returned.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String

The path to the files/directories to compress.

true false
OutDirectory String

Path to a directory where the file should be extracted.

false false
Force SwitchParameter

Overwrite any existing files/directories in OutDirectory.

false false False
WhatIf SwitchParameter false false
Confirm SwitchParameter false false
CommonParameters This cmdlet supports common parameters. For more information type
Get-Help about_CommonParameters.

Return Values

System.IO.DirectoryInfo.

EXAMPLE 1

$unzipRoot = Expand-Item -Path 'C:\Carbon.zip'

Demonstrates how to unzip a file into a temporary directory. You are responsible for deleting that directory.

EXAMPLE 2

Expand-Item -Path 'C:\Carbon.zip' -OutDirectory 'C:\Modules\Carbon'

Demonstrates how to unzip a file into a specific directory.

EXAMPLE 3

Expand-Item -Path 'C:\Carbon.zip' -OutDirectory 'C:\Modules\Carbon' -Force

Demonstrates how to decompress to an existing, non-empty directory with the -Force parameter. Existing files are overwritten.