How to unzip a file in Powershell?

前端 未结 9 2112
清歌不尽
清歌不尽 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:26

    In PowerShell v5.1 this is slightly different compared to v5. According to MS documentation, it has to have a -Path parameter to specify the archive file path.

    Expand-Archive -Path Draft.Zip -DestinationPath C:\Reference
    

    Or else, this can be an actual path:

    Expand-Archive -Path c:\Download\Draft.Zip -DestinationPath C:\Reference
    

    Expand-Archive Doc

    0 讨论(0)
  • 2020-11-29 17:27

    Use Expand-Archive cmdlet with one of parameter set:

    Expand-Archive -LiteralPath C:\source\file.Zip -DestinationPath C:\destination
    
    Expand-Archive -Path file.Zip -DestinationPath C:\destination
    
    0 讨论(0)
  • 2020-11-29 17:28

    ForEach Loop processes each ZIP file located within the $filepath variable

        foreach($file in $filepath)
        {
            $zip = $shell.NameSpace($file.FullName)
            foreach($item in $zip.items())
            {
                $shell.Namespace($file.DirectoryName).copyhere($item)
            }
            Remove-Item $file.FullName
        }
    
    0 讨论(0)
提交回复
热议问题