Create ISO of Cumulative Update with PowerShell – Get VersionInfo

Build_icon

This step is once again part of a bigger whole: turning your download of a Cumulative Update (CU) into an ISO image. In order to do that, I want to automate as much as possible: also the name and characteristics of the file that I’m creating. In order to do that, there is already a bunch of information that is in the naming convention that Microsoft applies to these Cumulative Updates. Remember my previous post, where I was unzipping the CU. Apparently, Microsoft puts the DVD in a zip-file, with a very specific naming convention, like “NAV.8.0.39663.BE.DVD.zip”, or “Product.majorversion.minorversion.build.country.DVD.zip”. This is interesting and useful information. So I decided to a new function that returns an object with this information. The function is called “Get-NAVCumulativeUpdateDownloadVersionInfo“. Yeah, I know, quite a long name .. I wanted to be really specific ;-).

Here is the function:

function Get-NAVCumulativeUpdateDownloadVersionInfo
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        [String] $SourcePath

    )

    Begin
    {
    }
    Process
    {
        $SourcePathZip = [io.path]::ChangeExtension($SourcePath,'zip')
        Rename-Item $SourcePath $SourcePathZip
        
        $helper = New-Object -ComObject Shell.Application
        $files = $helper.NameSpace($SourcePathZip).Items()
        $filename = ($files | where name -like '*zip').name

        $filename = [io.path]::GetFileNameWithoutExtension($filename)
        
        if ($SourcePath -ne $SourcePathZip) {
            Rename-Item $SourcePathZip $SourcePath
        }

        $regex = '(?<product>\w+?)\.(?<version>\d+?\.\d+?)\.(?<build>\d+?)\.(?<country>\w+?)\.DVD'
        $MatchedRegEx = [regex]::Match($filename, $regex)
        if (-not $MatchedRegEx.Success) {
            Write-Error "$filename in $SourcePath does not match the required format to be decompiled into versioninfo."
            break
        }
        $VersionInfo = New-Object System.Object
        $VersionInfo | Add-Member -MemberType NoteProperty -Name Product -Value $MatchedRegEx.Groups.Item('product').value
        $VersionInfo | Add-Member -MemberType NoteProperty -Name Version -Value $MatchedRegEx.Groups.Item('version').value
        $VersionInfo | Add-Member -MemberType NoteProperty -Name Build -Value $MatchedRegEx.Groups.Item('build').value
        $VersionInfo | Add-Member -MemberType NoteProperty -Name Country -Value $MatchedRegEx.Groups.Item('country').value
        $VersionInfo | Add-Member -MemberType NoteProperty -Name FullVersionString -Value $filename
    }
    End
    {
        $VersionInfo
    }
}

 

Basically, it’s going to search for the zip-file in the exe-file, and with regular expressions, it’s going to get the different tags out of it (thanks, Vjeko, for helping me with the regex :-)). Next, I build a simple object of it, and return it.
Second step in turning my download into an ISO is DONE! Up to the last step!

0.00 avg. rating (0% score) - 0 votes

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

2 pings

  1. […] Get VersionInfo from the downloaded Cumulative Update file. Microsoft applies a naming convention which we can use to create some kind of versioning info. This way, I will be able to automatically create a naming convention for my resulting ISO image. To determine this “versioninfo”, I created a separate function. […]

Leave a Reply to Create ISO of Cumulative Update with PowerShell – Get VersionInfo - Waldo's Blog - Microsoft Dynamics NAV Cancel reply

Your email address will not be published.

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