Home OS Deployment Microsoft Deployent Toolkit Importing Reference Operating System Images

Importing Reference Operating System Images

1837
0
Reading Time: 4 minutes

In this previous blog post, I covered creating the Reference Task Sequence and it deploying it, to be able to obtain our base Reference WIM File.

Now we have our initial Windows 10 1809 Reference Image we can import this into the ‘Production’ DeploymentShare – This deployment share contains all the device drivers and final applications which are required for end users and should ideally only contain production media which has passed QA/QoS Checks. This Blog post will cover the two types of Import.
1) Manually Importing the OS WIM File using the MDT MMC Window
2) Utilizing Microsoft PowerShell to Automatically import the WIM Media and update the Production Tasks sequences.

Manually Importing ‘Production-Ready’ Reference Images into MDT

From the DeploymentShare workbench, Navigate to ‘Operating Systems’

then on the right-hand side under the Action Tab select ‘Import Operating System’

Select ‘Custom Image File’

Select ‘Browse’

Select the WIM Image you want to Import

Select ‘Next’

Select ‘Next’

Define the Destination Folder Name.

Pre-Image Operating Summary.

Operating System Import In Progress.

Reference Image Import Complete.

Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
New-PSDrive -Name "DS002" -PSProvider MDTProvider -Root "D:\DeploymentShare"
import-mdtoperatingsystem -path "DS002:\Operating Systems\Windows 10\1809" -SourceFile "D:\ReferenceShare\Captures\REFWIN1064X-001-Win10Enterprise1809.wim" -DestinationFolder "REFWIN1064X-001-Win10Enterprise1809" -Verbose

Automating Reference Operating System Import

NOTE: You must already have an OS Image Imported and a Task Sequence Created for this solution to work!

The initial basis of this script i found from this blog post here and then adapted it to become fully automated as part of my enterprise reference patching sequence, below is a snipped down version for a single task sequence update and import.

<#
.NAME
    Microsoft Deployment Toolkit - Automated Operating System Import Script
.AUTHOR
    Simon Lee
    Blog: https://hypervlab.co.uk

.DESCRIPTION 
    Automate the OS Import from ReferenceShare to DeploymentShare

.NOTES
    Initial Import OSD SCiprt https://blog.paulw.io/32/how-to-use-powershell-to-change-the-operating-system-in-an-mdt-task-sequence/

.CHANGELOG
    Version 1.0 - Initial Script Created
#>

# Script Modules
Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"

# Script Variables
$MDTReferenceShare = 'D:\ReferenceShare'
$MDTDeploymentShare = 'D:\DeploymentShare'

#Reference Image Configuration
$RefImages = @(
    New-Object -TypeName psobject -Property @{
        # Windows 10 1809 Enterprise 
            REFTS   = 'REFWIN1064X-001'
            PRDTS   = 'PRD-WIN10-BASE64'
    }
)

# Create Powershell Drive for MDTRoot
New-PSDrive -Name "DS001" -PSProvider MDTProvider -Root "$MDTDeploymentShare" | Out-Null

ForEach ($Ts in $RefImages) {
    # OS Import Variables
    $RefWIMName = $TS.REFTS
    $RefWIMFile = $($Ts.REFTS) + ".wim"
    $OperatingSystem = "$RefWIMName" + "CDrive in $RefWIMName" + " " + "$RefWIMFile"

    # Remove Previous Reference Image from Production Share
    remove-item -path "DS002:\Operating Systems\Windows 10\1809\$OperatingSystem" -force -verbose
    
    # Import New Reference Image to Proudction Share
    import-mdtoperatingsystem -path "DS002:\Operating Systems\Windows 10\1809" -SourceFile "D:\ReferenceShare\Captures\$RefWimFile" -DestinationFolder "$RefWimName" -Verbose

    # Repalce OS Guid in Task Sequence
    $OSGuid = (Get-ItemProperty "DS002:\Operating Systems\Windows 10\1809\$OperatingSystem").guid
    $TSPath = "$MDTDeploymentShare\Control\$($Ts.PRDTS)\ts.xml"
    $TSXML = [xml](Get-Content $TSPath)
    $TSXML.sequence.globalVarList.variable | Where-Object { $_.name -eq "OSGUID" } | ForEach-Object { $_."#text" = $OSGuid }
    $TSXML.sequence.group | Where-Object { $_.Name -eq "Install" } | ForEach-Object { $_.step } | Where-Object {
        $_.Name -eq "Install Operating System" } | ForEach-Object { $_.defaultVarList.variable } | Where-Object {
        $_.name -eq "OSGUID" } | ForEach-Object { $_."#text" = $OSGuid }
    $TSXML.Save($TSPath)
    Write-Output ""
    Write-Output "OS Image Updated for: $($VM.PRDTaskSequence) Sequence"
}

For this script to work you need to define the following values:
$MDTReferenceShare – Folder Location for ReferneceShaare
$MDTProductionShare – Folder Location for DeploymentShareShaare
$REFTS – Reference Task Sequence
$PRDTS – Production Task Sequence

LEAVE A REPLY

Please enter your comment!
Please enter your name here