Create ISO of Cumulative Update with PowerShell – Unzip

This post is about the first “step” we need, regarding transforming a download of a cumulative update to an useful ISO file. This step handles on Unzipping the download, and putting it in some kind of destination folder.

When you download a CU, it looks something like this:


A self-extractable ZIP-file which contains:

  • a folder “APPLICATION”
  • and yet another ZIP file in the form of “NAV.8.0.39663.BE.DVD.zip”, which is the file we’re going to be interested in for eventually creating our ISO.

Our job for this part:

  • First, unzipping the exe-file
  • next, unzipping the zip of the DVD and removing the zip file (as this is not necessary anymore).

I created the function “Unzip-NAVCumulativeUpdateDownload“:

function Unzip-NAVCumulativeUpdateDownload
{
    [CmdletBinding()]
    Param
    (
        # The full source-filepath of the file that should be unzipped
        [Parameter(Mandatory=$true)] 
        $SourcePath,

        # The full Destionation-path where it should be unzipped
        [String] $DestinationPath
    )
    Process
    {       
        #rename exe to zip to be able to unzip it
        
        $SourcePathZip = [io.path]::ChangeExtension($SourcePath,'zip')
        Rename-Item $SourcePath $SourcePathZip | Out-Null
        
        Unzip-Item -SourcePath $SourcePathZip -DestinationPath $DestinationPath | Out-Null

        if ($SourcePath -ne $SourcePathZip) {
            Rename-Item $SourcePathZip $SourcePath | Out-Null
        }

        $ProductDVD = Get-ChildItem -Path $DestinationPath -Filter '*.zip'
        
        if ($ProductDVD){
            $SourcePath2 = $ProductDVD.FullName
            $DestinationPath2 = (join-path $ProductDVD.Directory ($ProductDVD.Name -replace '.zip',''))

            Unzip-Item -SourcePath $SourcePath2 -DestinationPath $DestinationPath2 | Out-Null
        } else
        {
            Write-Error 'Unknown file structure'
            break
        }
        Remove-Item -Path $SourcePath2 -Force | Out-Null
    }
    end
    {
        $DestinationPath2
    }
}

 

The function expects the format as described above, and is very simply going to:

  • Rename the exe to zip
  • Unzip the first zip
  • Search for the DVD-zip
  • Unzip that one as well
  • Remove the DVD-zip

And all in the end, it’s returning the DVD-folder, which I’m going to be interested in for turning into an ISO later on.

Now, to make this “Unzip” work, I need one other function: Unzip-Item, which expects a parameter being a zip-file, and a destination folder. There are multiple ways how to do it, and I found my solution online (though, can’t remember exactly the resource – my apologies for that). Here it is:

function Unzip-Item
{
    [CmdletBinding()]
    Param
    (
        # The full source-filepath of the file that should be unzipped
        [Parameter(Mandatory=$true, 
                   ValueFromPipelineByPropertyName=$true)]
        [Alias("Fullname")] 
        $SourcePath,

        # The full Destionation-path where it should be unzipped
        [String]
        $DestinationPath
    )
    process
    {
        if (-not (Test-Path $DestinationPath)){New-Item -Path $DestinationPath -ItemType directory}
        Unblock-File $DestinationPath 
        $helper = New-Object -ComObject Shell.Application
        $files = $helper.NameSpace($SourcePath).Items()
        $helper.NameSpace($DestinationPath).CopyHere($files) | Out-Null
    }
}

There you go .. you should now be able to already unzip your Cumulative Update with PowerShell. Up to the next step!

5.00 avg. rating (97% score) - 1 vote

Permanent link to this article: https://www.waldo.be/2015/05/25/create-iso-of-cumulative-update-with-powershell-unzip/

1 ping

  1. […] Create ISO of Cumulative Update with PowerShell – Unzip » […]

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.