How to unzip big archives in Powershell DSC configurations

How to unzip big files in Powershell DSC configurations

If you ever need to unzip BIG archive files in Powershell DSC configurations (during deployment some software), you will possibly get stuck, because using Archive resource is not suitable for this task as it is very slow. xArchive also will not help.

One possible solution is to unzip it with 7zip or some other command line utility using WindowsProcess resource, but be warned that WindowsProcess will just start the process and then will go to the next instruction in your configuration. See the example:

 

WindowsProcess ExtractSolr {
    Path = "c:\distrib\7z\7za.exe";
    Arguments = "x c:\distrib\solr\solr-6.3.0.zip -oc:\ -y";
}

WindowsProcess ExtractJava {
    Path = "cmd.exe";
    Arguments = "/C c:\distrib\7z\7za.exe x c:\distrib\java\server-jre-8u112-windows-x64.tar.gz -so | c:\distrib\7z\7za.exe x -aoa -si -ttar -oc:\java";
}

In this particular case, Java will be extracted EARLIER than Solr. If you have any important dependencies in your code, this will lead to errors.

So, I've dealt with the issue in the following way:

Script ExtractSolr {
    SetScript = {        
        New-Item -Path "C:\solr-6.3.0" -ItemType Directory;
        Expand-Archive -Force -Path "c:\distrib\solr\solr-6.3.0.zip" -DestinationPath "C:\";
    }

    TestScript = {
        (Test-Path -Path "C:\solr-6.3.0");
    }

    GetScript = {
        #Do Nothing                
    }
}

Using Script resourse, any subsequent instructions will not be executed.

powershell (en), dsc (en)

  • Hits: 6058
Add comment

Related Articles