Unpack a collection of CAB files

When setting up slipstreamed updates, you first get the updates from Microsoft using WSUS, in CAB format.  The setup routine want them to be MSI files, so this routine unpacks the MSI files from inside the CAB files.

[Powershell code]
#  Author: Roger C
#    Date: 23-Oct-2016 
# Version: 1.1.0.0
# Purpose: Unpack a collection of cab files in subfolders as provided by WSUS/SCCM
# this allows us to maintain a collection of MSI files for Office 2016 for slipstreaming into the installation

# enable debugging output if desired
$DebugPreference = "SilentlyContinue" #"Continue" 

$cabPath="C:\Scripts\Download\Slipstream Updates\"
#$cabPath="\\of-fs-02.expn.corp\sccmsource$\Desktop\Software Updates\Office 2016"
$destination="C:\Scripts\Download\Slipstream Updates\unpacked\test"
$cabs=Get-ChildItem -path $cabpath -recurse -include "*.cab"
ForEach ($cab in $cabs) {
    if (test-path ($destination + "\" + $cab.basename + ".msp")) {
        Write-Host "Skip: " ($destination + "\" + $cab.name)
    } else {
        Write-Host "Unpack: " ($destination + "\" + $cab.name)
        ConvertFrom-Cab -FullName $cab.Fullname -destination $destination
        Remove-Item  ($destination + "\" + $cab.basename + ".xml") # throw away the XML file
    }
}

Function ConvertFrom-Cab {
    [cmdletbinding()]
    Param(            
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$FullName,
        [string]$destination
    )
    $comObject = "Shell.Application"
    Write-Debug "Creating $comObject"
    $shell = New-Object -Comobject $comObject
    if(!$?) { $(Throw "unable to create $comObject object")}
    Write-Debug "Creating source cab object for $cab"
    $sourceCab = $shell.Namespace($FullName).items()
    Write-Debug "Creating destination folder object for $destination"
    $DestinationFolder = $shell.Namespace($destination)
    Write-Debug "Expanding $FullName to $destination"
    $DestinationFolder.CopyHere($sourceCab)
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s