Batch-Unzipping Files

Thanks to for the core code.

Here's a function to unzip files, with rudimentary error handling, and ability to specify source and destination from the command line.  It also brute-forces the "overwrite flag fails on pre-Win7" issue by allowing -force to unzip to a temp folder, then moves the contents of that folder forcibly over the destination, effectively overwriting the existing files if possible.

function Unzip-Item {
    param (
        [String[]]$path = $([String[]](Get-ChildItem "*.zip")),
        $dest = '.',
    if ($force) {
        $oldDest = $dest;
        $dest = "$env:temp\unzip-item_{0}" -f (Get-Date -Format 'yyyyMMddhhmmss');
        mkdir $dest | Out-Null;       
    $shApp = New-Object -ComObject Shell.Application;
    $destObj = $shApp.NameSpace((Resolve-Path $dest).Path);
    if (!$path) {
        Write-Warning "-path does not contain any zip files.  Returning";
    foreach ($_ in $path) {
        $zipPath = (Resolve-Path $_).Path;
        if (!($zipPath -match "\.zip$")) {
            Write-Warning "-path $_ is not a .zip file.  Skipping.";
        $zipObj = $shApp.NameSpace($zipPath);
        if ($zipObj) {
        } else {
            Write-Warning "Unable to find file $_.  Skipping.";
    if ($force) { Move-Item -Path "$dest\*" -Destination $oldDest -Force; }




Comments (0)

Skip to main content