HOWTO · PowerShell

PowerShell Unzip

This article introduces how to unzip a zip file in powershell.

On this page

To extract a ZIP archive in PowerShell, use Expand-Archive with the archive path and, when needed, a destination. For example, Expand-Archive -Path .\backup.zip -DestinationPath .\restored extracts the archive into the restored folder. The cmdlet extracts files and folders; it does not create a ZIP archive.

Extract a ZIP archive with Expand-Archive

Expand-Archive accepts an archive path and an optional destination path. The destination folder is created when it does not already exist. Choose a destination you can identify and access, especially when extracting an archive from an unfamiliar source. ZIP archives can contain multiple files and folders, so check the destination contents before opening or using extracted files.

Choose -Path or -LiteralPath

Use -Path when the archive path may use wildcard characters to match a path. Use -LiteralPath when PowerShell should treat the supplied path as written, including characters such as square brackets. For a file named backup[v1].zip, pass the path with -LiteralPath; with -Path, the brackets may be interpreted as wildcard syntax rather than as part of the filename. Quoting a value helps PowerShell pass it as one argument, but it does not turn wildcard-aware -Path into a literal path.

Set the destination and handle existing files

Pass -DestinationPath with the folder where extracted content should go. If you omit it, Expand-Archive creates a folder named after the archive in the current location and extracts the contents there. Set -DestinationPath explicitly when you want predictable placement and easier cleanup.

Extraction can fail when files from the archive already exist at the destination. -Force permits replacement of existing data. Use it only when overwriting those files is intended; inspect or back up important destination contents first. It is not merely a way to suppress a confirmation prompt.

If extraction cannot locate the archive, check the current working directory and whether the path is relative or absolute. Confirm the spelling and extension, and use -LiteralPath if the name contains wildcard characters. If the archive is found but the result is not where expected, set -DestinationPath explicitly and inspect that folder. You can add -WhatIf to preview a command before running it; remove that switch when you are ready to extract. -Confirm requests confirmation for the operation, while -PassThru returns information about extracted files for further handling in a PowerShell pipeline.

Common Expand-Archive parameters

Parameter Use
-Path Supplies an archive path that can interpret wildcard characters.
-LiteralPath Supplies an archive path treated literally, including wildcard characters in a file name.
-DestinationPath Selects the folder for extracted content.
-Force Permits replacement of existing data at the destination; use with care.
-WhatIf Previews the operation without carrying it out.
-Confirm Requests confirmation before the operation.
-PassThru Returns information about extracted files.

Examples: Extract ZIP files in PowerShell

Run this self-contained example in PowerShell. It creates a small archive in a temporary directory, extracts it to a separate folder, and displays the extracted text.

$root = Join-Path ([IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString('N'))
$source = Join-Path $root 'source'
$destination = Join-Path $root 'extracted'
$archive = Join-Path $root 'sample.zip'
New-Item -ItemType Directory -Path $source -Force | Out-Null
Set-Content -LiteralPath (Join-Path $source 'notes.txt') -Value 'Archive ready'
Compress-Archive -LiteralPath (Join-Path $source 'notes.txt') -DestinationPath $archive
Expand-Archive -LiteralPath $archive -DestinationPath $destination
Get-Content -LiteralPath (Join-Path $destination 'notes.txt')
Remove-Item -LiteralPath $root -Recurse -Force
Archive ready

For an existing archive, use Expand-Archive -Path .\backup.zip -DestinationPath .\restored to extract it to a chosen folder. If the path itself contains wildcard characters, switch to -LiteralPath, as in Expand-Archive -LiteralPath 'C:\Archives\backup[v1].zip' -DestinationPath 'C:\Restored'. The self-contained example above ran successfully and printed Archive ready (exit code 0). The command forms in this paragraph are examples to adapt to your archive and destination.