Peter Hinchley

Learning in Public

✪ Configure a Task Sequence in SCCM 2012 R2 SP1 using PowerShell

In this article I will demonstrate how to use PowerShell to deploy a previously captured operating system image using Microsoft Configuration Manager 2012 R2 SP1.

This post is a continuation of a series of articles that describe the installation of SCCM 2012 R2 SP1, post-installation configuration of SCCM, and the installation and configuration of MDT 2013.

To import a captured operating system image (i.e. captured via MDT) into SCCM:

Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"  
Set-Location LAB:

$SiteCode   = (Get-CMSite).SiteCode
$SiteServer = (Get-CMSite).ServerName

New-CMOperatingSystemImage -Name "Windows 10" -Path "\\\Software\Operating System Images\Windows 10\Windows 10.wim"

To copy the content in this package to a package share, enable binary differential distribution, and to actually distribute the package to the distribution point on the primary site server:

Set-CMOperatingSystemImage -Name "Windows 10" -CopyToPackageShareOnDistributionPoint $true -EnableBinaryDeltaReplication $true
Start-CMContentDistribution -OperatingSystemImageName "Windows 10" -DistributionPointName $SiteServer

Unfortunately, we can't customise the default WinPE 10 boot images using the native SCCM 2012 cmdlets. To overcome this issue, we will use WMI to copy the images to a package share, enable differential distribution, and also to enable F8 command support:

Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_BootImagePackage | %{
  $image = [wmi]"$($_.__PATH)"
  # enable F8 command support
  $image.EnableLabShell = $true
  # copy to package share
  $image.PkgFlags = $image.PkgFlags -bor 0x00000080
  # differential replication
  $image.PkgFlags = $image.PkgFlags -bor 0x04000000

And now we can distribute the boot images:

Get-CMBootImage | %{
  Start-CMContentDistribution -BootImageName $_.Name -DistributionPointName $SiteServer

To ensure we can run task sequences directly from a distribution point, it is necessary that all packages referenced by a task sequence are copied to a package share. Unfortunately, the default Configuration Manager package is "locked" and the copy to package share property cannot be set. To overcome this issue, we will create a new version of the package:

$Client = "Microsoft Configuraiton Manager Client"
New-CMPackage -Name $Client -Path "\\$SiteServer\SMS_$SiteCode\Client"
Set-CMPackage -Name $Client -CopyToPackageShareOnDistributionPoint $true -EnableBinaryDeltaReplication $true
Start-CMContentDistribution -PackageName $Client -DistributionPointName $SiteServer

The next step is to create a task sequence for deploying the operating system:

New-CMTaskSequence -InstallOperatingSystemImageOption `
  -TaskSequenceName "Windows 10" `
  -BootImagePackageId (Get-CMBootImage -Name "Boot image (x64)").PackageID `
  -OperatingSystemImagePackageId (Get-CMOperatingSystemImage -Name "Windows 10").PackageID `
  -OperatingSystemImageIndex 1 `
  -ClientPackagePackageId (Get-CMPackage -Name "Microsoft Configuraiton Manager Client").PackageID `
  -JoinDomain DomainType `
  -DomainName "" `
  -DomainAccount "LAB\administrator" `
  -DomainPassword (Read-Host "Domain Join Password" -AsSecureString) `
  -DomainOrganizationUnit "LDAP://OU=Workstations,DC=lab,DC=hinchley,DC=net" `
  -PartitionAndFormatTarget $true `
  -LocalAdminPassword (Read-Host "Local Admin Password" -AsSecureString)

And finally, we will create a deployment for the task sequence, advertising the operating system to All Unknown Computers:

Start-CMTaskSequenceDeployment `
  -TaskSequencePackageId (Get-CMTaskSequence -Name "Windows 10").PackageID `
  -CollectionName "All Unknown Computers" `
  -DeployPurpose Available `
  -Availability MediaAndPxe `
  -ShowTaskSequenceProgress $true `
  -DeploymentOption RunFromDistributionPoint
  -AllowFallback $false
  -AllowSharedContent $false

Assuming you have DHCP enabled on your network, try PXE-booting a virtual machine - you should see an option to deploy Windows 10 via SCCM.