New-OSDriverCAB.ps1
<#
.LINK https://www.osdeploy.com/psmodule/osdrivers/ .SYNOPSIS Creates a CAB file from a Directory or Child Directories .DESCRIPTION Creates a CAB file from a Directory or Child Directories .PARAMETER Path Directory to create the CAB from .PARAMETER HighCompression Forces LZX High Compression (Slower). Unchecked is MSZIP Fast Compression .PARAMETER MakeCABsFromSubDirs Creates CAB files from Path Subdirectories .EXAMPLE New-OSDriverCAB -Path C:\Temp\Dell\LatitudeE10_A01 Creates MSZIP Fast Compression CAB from of C:\Temp\Dell\LatitudeE10_A01 .EXAMPLE New-OSDriverCAB -Path C:\Temp\Dell -HighCompression -MakeCABsFromSubDirs Creates LZX High Compression CABS from all subdirectories of C:\Temp\Dell .NOTES NAME: New-OSDriverCAB.ps1 AUTHOR: David Segura, david@segura.org BLOG: http://www.osdeploy.com CREATED: 02/18/2018 VERSION: 1.1.0.2 #> function New-OSDriverCAB { [CmdletBinding()] Param ( [Parameter(Mandatory=$True)] [string]$Path, [switch]$HighCompression, [switch]$MakeCABsFromSubDirs ) If ($HighCompression) { $Compress = ".Set CompressionType=LZX" } Else { $Compress = ".Set CompressionType=MSZIP" } If ($MakeCABsFromSubDirs) { Get-ChildItem -Directory -Path $Path | ForEach ($_) { PSMakeCAB $_.FullName } } Else { PSMakeCAB $Path } } function PSMakeCAB($Path) { #Set the CAB File Name $CabFileName = (Get-Item $Path).Name $CabFileNameExt = (Get-Item $Path).Name + ".cab" #Set the Destination Directory $DestinationDir = (Get-Item $Path).Parent.FullName Write-Host "Creating " $DestinationDir\$CabFileNameExt $ddf = ";*** MakeCAB Directive file; .OPTION EXPLICIT .Set CabinetNameTemplate=$CabFileNameExt .Set DiskDirectory1=$DestinationDir .Set Cabinet=on .Set Compress=on $Compress .Set CabinetFileCountThreshold=0 .Set FolderFileCountThreshold=0 .Set FolderSizeThreshold=0 .Set MaxCabinetSize=0 .Set MaxDiskFileCount=0 .Set MaxDiskSize=0 " $PathFullName = (Get-Item $Path).fullname #Remove Streams Get-ChildItem $PathFullName -Recurse | Unblock-File $ddfpath = ($DestinationDir+"\$CabFileName.ddf") $ddf += (ls -recurse $Path | ? {!$_.psiscontainer}|select -expand fullname|%{'"'+$_+'" "'+$_.SubString($PathFullName.length+1)+'"'}) -join "`r`n" $ddf $ddf | Out-File -encoding UTF8 $ddfpath makecab /F $ddfpath #rm $ddfpath #rm setup.inf #rm setup.rpt } |