Duplicate Drivers from a ConfigMgr Boot Image

When creating new boot images in ConfigMgr, you often want to copy drivers from an older boot image. If you have many drivers added, it's way quicker to do that in PowerShell compared to comparing drivers in the boot image drivers tab. Here is a script for that

Drivers in the OLD Boot image.
# Script to Duplicate Drivers from one boot image to another
$SourceBootImageName = "OLD Boot image (x64)"
$DestinationBootImageName = "NEW Boot image (x64)"

# Site configuration
$SiteCode = "PS1" # Site code 
$ProviderMachineName = "CM01.corp.viamonstra.com" # SMS Provider machine name

# Import the ConfigurationManager.psd1 module 
if((Get-Module ConfigurationManager) -eq $null) {
    Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" 
}

# Connect to the site's drive if it is not already present
if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {
    New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName 
}

# Set the current location to be the site code.
Set-Location "$($SiteCode):\" 

# Get boot images
$SourceBootImage = Get-CMBootImage -Name $SourceBootImageName
$DestinationBootImage = Get-CMBootImage -Name $DestinationBootImageName


# Validation
If (!($SourceBootImage)){
    Write-Warning "Source Boot image not found, aborting..."
    Break
}
If (!($DestinationBootImage)){
    Write-Warning "Destination Boot image not found, aborting..."
    Break
}


# Get ID and drivers from source boot image 
$SourceBootImageID = $SourceBootImage.PackageID
$SourceBootImageDrivers = $SourceBootImage.ReferencedDrivers

# Get ID destination boot image 
$DestinationBootImageID = $DestinationBootImage.PackageID

Write-Host "Copying drivers from boot image $SourceBootImageID to $DestinationBootImageID " 

foreach ($Driver in $SourceBootImageDrivers){
    # Get Details
    $DriverDetails = Get-CMDriver -Id $Driver.ID -Fast
    Write-Host "Name: $($DriverDetails.LocalizedDisplayName)"
    Write-Host "SourcePath: $($DriverDetails.ContentSourcePath)"
    Write-Host "Inf File: $($DriverDetails.DriverINFFile)"
    Write-Host "Date: $($DriverDetails.DriverDate)"
    Write-Host "Version: $($DriverDetails.DriverVersion)"
    Write-Host "" 

    # Add drivers to destination boot image
    Set-CMDriverBootImage -DriverId $Driver.ID -Verbose -BootImageName $DestinationBootImageName -SetDriveBootImageAction AddDriverToBootImage

}

Drivers in the NEW boot image after running the script.
About the author

Johan Arwidmark

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted

>