Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Best way to unzip files in Deploy?

Powershell or other?

0

Comments

4 comments
Date Votes
  • If your targets have PowerShell 5 you can use Expand-Archive. https://stackoverflow.com/a/27771099

    If not, you can build a function that calls .NET. https://stackoverflow.com/a/27768628

    Add-Type -AssemblyName System.IO.Compression.FileSystem
    function Unzip
    {
        param([string]$zipfile, [string]$outpath)
    
        [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
    }
    
    Unzip "C:\a.zip" "C:\a"
    0
  • I have this in my PS Profile so that when I'm working with <v5 powershell systems I can easily zip/unzip stuff. Works pretty well:

     

    Add-Type -AssemblyName System.IO.Compression.FileSystem

    function Unzip-File

    {

        param ([string]$Source,

            [string]$Destination)

        

        [System.IO.Compression.ZipFile]::ExtractToDirectory($Source, $Destination)

    }

    Function Zip-File

    {

    param([string]$Source,[string]$Destination)

    [System.IO.Compression.ZipFile]::CreateFromDirectory($Source,$Destination)

     

    }
    0
  • Hey Colby,

     

    I finally got back around to trying your method, and it does work, if the files don't exist. How do I tell it to overwrite. 

     

    Sorry, still new to powershell....

    0
  • Which method? Expand-Archive or the Unzip function from StackOverflow?

    0