How to unzip a file in Powershell?

前端 未结 9 2155
清歌不尽
清歌不尽 2020-11-29 17:07

I have a .zip file and need to unpack its entire content using Powershell. I\'m doing this but it doesn\'t seem to work:

$shell = New-Object -Co         


        
9条回答
  •  半阙折子戏
    2020-11-29 17:19

    For those, who want to use Shell.Application.Namespace.Folder.CopyHere() and want to hide progress bars while copying, or use more options, the documentation is here:
    https://docs.microsoft.com/en-us/windows/desktop/shell/folder-copyhere

    To use powershell and hide progress bars and disable confirmations you can use code like this:

    # We should create folder before using it for shell operations as it is required
    New-Item -ItemType directory -Path "C:\destinationDir" -Force
    
    $shell = New-Object -ComObject Shell.Application
    $zip = $shell.Namespace("C:\archive.zip")
    $items = $zip.items()
    $shell.Namespace("C:\destinationDir").CopyHere($items, 1556)
    

    Limitations of use of Shell.Application on windows core versions:
    https://docs.microsoft.com/en-us/windows-server/administration/server-core/what-is-server-core

    On windows core versions, by default the Microsoft-Windows-Server-Shell-Package is not installed, so shell.applicaton will not work.

    note: Extracting archives this way will take a long time and can slow down windows gui

提交回复
热议问题