A Week of Task Sequence Tips - Day 03 - Variables Gather and Capture

We reached tip three, what tip do I have up my sleeve today? One word: Variables. You use them more than you might think. Many of you come to expect and rely on, but then you uninstalled MDT, or didn't install it in your new ConfigMgr setup, and your Task Sequence steps started to fail.

The Community has created a great script that auto generates a ton of useful variables, and I've implemented it in all of my task sequences. The script is also useful when you want to figure out how this information was gathered, as the creator of the script is a guru at powershell and you can learn a far amount from the script itself. Here are some of the additional variables created:

  • Architecture
  • AssetTag
  • BIOSReleaseDate
  • BIOSVersion
  • DefaultGateway
  • IPAddress
  • IsDesktop
  • IsLaptop
  • IsOnBattery
  • IsServer
  • IsVM
  • MacAddress
  • Memory
  • Model
  • OSCurrentBuild
  • OSCurrentVersion
  • ProcessorSpeed
  • Product
  • SerialNumber
  • UUID
  • Vendor
  • VMPlatform

So now you've got lots of variables, and you're trying to set your own. You want to confirm that they are set, and that they are what you're expecting. You can either than Pause the Task Sequence, (like we talked about in the last post) launch powershell and read the variables, or run a script that dumps all the variables to a log file. Nice thing is, this script skips sensitive variables that might include passwords and gives you the peace of mind that if someone opens the log, they won't find any info that you'd consider risky.

So what does this look like in the Task Sequence?

Gather Script
Gather Script
Dump Variable Script
Dump Variable Script

And the Output?

TSVariables Logs
TSVariables Logs

The Script create a log file in the SMSTSLog folder, which gets commmited to the logs folder after the TS is completed.

Bonus.. registry keys..

Ever want to check a registry key value at a specific time... write the value to a task sequence variable! Then you can read that variable.

This step grabs the Value of a Specific Key and places it in a TS Variable
This step grabs the Value of a Specific Key and places it in a TS Variable
powershell.exe -command "$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('RegKeyTest1') = Get-ItemPropertyValue 'HKLM:SOFTWARE\WaaS\setupdiag\18362' 'UpgradeEndTime'"

So that was a nifty tip, creating variables, outputting variables to a log file, reading registry keys into variables, that's handy stuff! See you next time... and remember to connect with me @RecastSoftware on Twitter.

See more tips:

Day 01 - Tag Version in Description

Day 02 - Task Sequence Pause