hacking the task sequence - schedschd.ws/hosted_files/mms2015/43/hacking the task sequence...
TRANSCRIPT
Hacking the Task Sequence2015
Daniel Ratliff
@potentengineer
Mike Terrill
@miketerrill
#MMSMOA
@potentengineer
Technology Architect LouSMUG10+ years
Louisville, KY
Daniel Ratliff
#MMSMOA
@miketerrill
Product Manager AZSMUG18+ years
Phoenix, AZ
Mike Terrill
Goals of the Session
• Share ideas and experiences
• Provide tips and tricks
• Promote best practice ideas and new ways of solving problems
• Automate tasks from simple to daunting
• Have fun!
Agenda
• Overview
• Pausing the Task Sequence
• Listing & Setting Task Sequence Variables
• Set Dynamic Variables – hidden gem
• Documenting Task Sequence Classes
• Documenting Task Sequence Steps
• Adding/Removing Task Sequence Step
• Editing multiple Task Sequences
Overview
Hack [hak]“To devise or modify (a computer program), usually skillfully.”
-Dictionary.com
Task Sequence Variables
Always include certain files in your Boot Images
• Put CMTrace.exe in the path• SMSTS.INI• Company background image• ServiceUI.exe• Other scripts or utilities that do not change often
NOTE: Keep them small so you do not bloat the size of the boot image
Future upgrades and service packs may overwrite changes
See References for blog link
Pausing the Task Sequence
Interactive cmd prompt with cmd
cmd.exe /c "start /wait cmd.exe"
Interactive cmd prompt using ServiceUI (e.g. under
old OS of a Refresh build)
"%toolroot%\ServiceUI.exe" -process:tsprogressui.exe
"%WINDIR%\System32\cmd.exe"
Pausing the Task Sequence – On Content Steps
Use SMSTSDownloadProgram to Pause the Task
Sequence:
Set Task Sequence Variable SMSTSDownloadProgram to either:
Baremetal:
cmd.exe /c "start /wait cmd.exe"
Refresh:
"%WINDIR%\ServiceUI.exe" -process:tsprogressui.exe
"%WINDIR%\System32\cmd.exe"
(Make it simple and copy the correct platform version of
ServiceUI.exe to %WINDIR% on test system and Boot Image)
Listing Task Sequence Variables
Can be done with a simple VBScript:
Set osdvars=createobject("Microsoft.SMS.TSEnvironment")
For each var in osdvars.getvariables
Wscript.echo var & "=" & osdvars(var)
Next
Listing Task Sequence Variables
Can be done with PowerShell:
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$tsenv.GetVariables() | % { Write-Host "$_ = $($tsenv.Value($_))" }
Requires PowerShell and .Net Framework components in the Boot Image
Boot Image size goes from ~260 MB to ~375 MB
Listing & Setting Task Sequence Variables
Or it can be done with TSEnv2 (available to
1E Nomad customers):
TSEnv2.exe list
TSEnv2.exe list > osdvars.txt
TSEnv2.exe get _SMSTSMDataPath
Set Dynamic Variables – Hidden Gem
Available starting with ConfigMgr 2012 R2
Adds:
_SMSTSMake
_SMSTSModel
_SMSTSMacAdresses (not Addresses)
_SMSTSIPAddresses
_SMSTSDefaultGateWays
_SMSTSSerialNumber
_SMSTSAssetTag
_SMSTSUUID
Task Sequence Variables & x64 Boot Images
• Microsoft.SMS.TSEnvironment is not available between Pre-start & Running Task Sequence
• Normally this is not a problem – but for testing Prestart development it can be
• Solution – launch a cmd /k from Prestart and the TSEnvironment will be available
• See DeploymentRamblings blog for more information
DemoTask Sequence Variables
Documenting Task Sequences
Export-CMTaskSequenceStepClasses
• Creates reference .csv for all iResultObject classes
• Identifies all properties specific to each class• e.g, RunCommandLine, PackageID, ProgramName
• Identifies all property types• e.g, Boolean, string, int32, array
• Used to build all functions in CMTaskSequenceEditor.psm1
Export-CMTaskSequenceStepClasses output
Old hat - Task Sequence Documentor v2
New hat – Get-CMTaskSequenceSteps
Comparison
Task Sequence Documentor v2 Get-CMTaskSequenceSteps
Output XML stylesheet (.xml + .xsl) Comma-separated value file (.csv)
Output modification Limited to stylesheet modification for
formatting
Limited only by PowerShell & Excel
Editable content Not easily, requires .xml modification Yes, object based input
Steps indexed No Yes, in consecutive order
Shareable Yes, with instructions. Can only be
displayed in Internet Explorer.
Yes, just a .csv file
Get-CMTaskSequenceSteps notes
Gotchyas!• Still in development!
• TS steps with multiple if conditions are not documented properly (multiple conditions with a single if statement work fine)
• Nested groups are not displayed as nested
• Some passwords are plain text! (MDT Configure ADDS)
DemoDocumenting TS steps
Editing Task Sequences
Add-CMTaskSequenceStep
• Adds a step to a task sequence at the specified index
• If no index is specified step is added to end of TS
• Accounts for the following step types• Run Command Line
• Install Package
• Install Application
• Group
• Use step index from Get-CMTaskSequenceSteps output
Add-CMTaskSequenceStep examples
Add-CMTaskSequenceStep -SiteServer CM01 -SiteCode CM1 -TaskSequencePackageIDCM10001B -StepType RunCommandLine -Name "Run a command" -CommandLine "cmd /c md c:\temp"
This example creates a Run Command Line step with the default parameters
Add-CMTaskSequenceStep -SiteServer CM01 -SiteCode CM1 -TaskSequencePackageIDCM10001B -StepType RunCommandLine -Name "Run a command" -CommandLine "cmd /c md c:\temp" -StepIndex 8
This example creates a Run Command Line step with the default parameters as the
8th step in the task sequence
Add-CMTaskSequenceStep notes
Gotchyas!• Still in development, lots of functionality to be added in time
• Does not check if task sequence is open (read-only)
• Cannot add conditions
• Does not account for all task sequence steps
• Install Application step cannot add multiple Apps easily (array of apps are required)
Remove-CMTaskSequenceStep
• Removes a step to a task sequence at the specified index
• Does not remove groups by default
• Use –force to remove a group and all child steps
• Use step index from Get-CMTaskSequenceSteps output
Remove-CMTaskSequenceStep examples
Remove-CMTaskSequenceStep -SiteServer CM01 -SiteCode CM1 `
-TaskSequencePackageID CM10000A -StepIndex 5
This example removes the 5th step in the task sequence
Remove-CMTaskSequenceStep -SiteServer CM01 -SiteCode CM1 `
-TaskSequencePackageID CM10000A -StepIndex 4 -Force
This example removes the 4th step in the task sequence and forces removal if
the step is a group
Remove-CMTaskSequenceStep notes
Gotchyas!•Still in development, lots of functionality to be added in time
•Does not prompt for removing large groups
•Cannot remove steps nested below 2 or more groups
DemoAdding/removing TS steps
Module: CMTaskSequenceEditor.psm1
Import-Module '.\CMTaskSequenceEditor.psm1'
• Still in development, lots of functionality to be added in time
• Includes the following functions:
• Export-CMTaskSequenceStepClasses
• Get-CMTaskSequenceSteps
• Add-CMTaskSequenceStep
• Remove-CMTaskSequenceStep
• Future functions
• Move-CMTaskSequenceStep (Move an existing step)
• Set-CMTaskSequenceStep (Edit an existing step)
• Will be available on TechNet gallery after MMS
Other Sessions
• Automating End To End Image Creation with MDT and PowerShell (Tuesday, November 10th at 2:00 PM)
• Real World Windows Deployments with Dell & 1E (Monday, November 9th at 1:00 PM)
• Making the switch from BIOS to UEFI (Wednesday, November 11th at 4:00 PM)
• MMS Every Month at Home – User Groups (Wednesday, November 11th at 6:00 PM)
References
• Task Sequence Documentor• Task Sequence Documentor v2• Using the Task Sequence Documentor with PowerShell
• Task Sequence Editing community resources• Ben Burckart – Adding a step to a task sequence - PowerShell• TechNet forums – Adding a step to a task sequence - PowerShell• J. Greg – OSD Driver handling in a task sequence - PowerShell• Nigel Wright – Adding a step to a task sequence – SDK
• Microsoft resources• ConfigMgr 2012 R2 SDK download• MSDN - OSD Task Sequence SDK• MSDN - OSD WMI Classes SDK
References
• ConfigMgr 2012: Always including certain files in your Boot Images
• Task Sequence Built-in Variables in Configuration Manager
• WinPE 5.0 x64: Microsoft.SMS.TSEnvironmentUnavailable?
• 1E Free Tools
Blogs
• www.potentengineer.com
• miketerrill.net
Evaluations: Please provide session feedback by clicking the EVAL button in the scheduler app (also
download slides). One lucky winner will receive a free ticket to the next MMS!
Hacking the Task Sequence 2015
Discuss…
Ask your questions-real world answers!
Plenty of time to engage, share knowledge.
SPONSORS