Search code examples
powershellbatch-fileunzip

Powershell unzip file with .zip extension and move it to another folder


I hope some of you can help me. I got stuck modifying a powershell script.

The script checks for a zip file (file name is a fix value) in a specific folder (origin) and moves it to another folder (destination), however I need a script which checks for the .zip extension, not a fix value and moves it to another folder as well. I'm using this script at the moment:

powershell.exe -nologo -noprofile -command "& { $shell = New-Object -COM Shell.Application; $target = $shell.NameSpace('D:\Anlagen'); $zip = $shell.NameSpace('C:\Temp\Rechnungen\Outlook'); $target.CopyHere($zip.Items(), 16); }"

As you can see I need this script as a batch.file.


Solution

  • Use Expand-Archive to unzip the file to a directory, and then from your batch script, copy the files somewhere else. If you need to do this from a batch script:

    powershell.exe -c "Expand-Archive -Path 'C:\path\to\archive.zip' -DestinationPath 'C:\unzip\directory'"
    xcopy /s /e /t "C:\unzip\directory" "C:\final\destination\directory"
    

    Note that UNC paths should also work with either command, not just local paths.