hacking the task sequence - schedschd.ws/hosted_files/mms2015/43/hacking the task sequence...

39
Hacking the Task Sequence 2015 Daniel Ratliff @potentengineer [email protected] Mike Terrill @miketerrill [email protected]

Upload: donhan

Post on 09-Mar-2018

312 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Hacking the Task Sequence2015

Daniel Ratliff

@potentengineer

[email protected]

Mike Terrill

@miketerrill

[email protected]

Page 2: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

#MMSMOA

@potentengineer

Technology Architect LouSMUG10+ years

Louisville, KY

Daniel Ratliff

Page 3: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

#MMSMOA

@miketerrill

Product Manager AZSMUG18+ years

Phoenix, AZ

Mike Terrill

Page 4: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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!

Page 5: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 6: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Overview

Hack [hak]“To devise or modify (a computer program), usually skillfully.”

-Dictionary.com

Page 7: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Task Sequence Variables

Page 8: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 9: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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"

Page 10: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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)

Page 11: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 12: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 13: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 14: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Set Dynamic Variables – Hidden Gem

Available starting with ConfigMgr 2012 R2

Adds:

_SMSTSMake

_SMSTSModel

_SMSTSMacAdresses (not Addresses)

_SMSTSIPAddresses

_SMSTSDefaultGateWays

_SMSTSSerialNumber

_SMSTSAssetTag

_SMSTSUUID

Page 15: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 16: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

DemoTask Sequence Variables

Page 17: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Documenting Task Sequences

Page 18: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 19: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Export-CMTaskSequenceStepClasses output

Page 20: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Old hat - Task Sequence Documentor v2

Page 21: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

New hat – Get-CMTaskSequenceSteps

Page 22: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 23: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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)

Page 24: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

DemoDocumenting TS steps

Page 25: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Editing Task Sequences

Page 26: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 27: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 28: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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)

Page 29: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 30: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 31: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 32: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

DemoAdding/removing TS steps

Page 33: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 34: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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)

Page 35: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 36: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 37: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

Blogs

• www.potentengineer.com

• miketerrill.net

Page 38: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com

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

Page 39: Hacking the Task Sequence - Schedschd.ws/hosted_files/mms2015/43/Hacking the Task Sequence 2015.pdfHacking the Task Sequence 2015 Daniel Ratliff @potentengineer daniel.ratliff@gmail.com