Jump to content






Recommended Posts

OSD Run Command Line: WMI to TS Variable

(Tested with WinPE 1703 and Windows 10 1703 / SCCM 2012 Version 1706 / MDT )

A short guide how to store WMI information into a Task Sequence Variable without the need of a script. (And therefore without a "Update Distribution Point")

  • Create a new "Run Command Line" Step
  • Set the step name for example: "Set Task Sequence Variable OSD_VariableName"
  • Command Line:
powershell -Command "& {(New-Object -COMObject Microsoft.SMS.TSEnvironment).Value('OSD_VariableName') = (Get-WmiObject Win32_ComputerSystemProduct).Version}"
  • Done

The example shows how to store the property "Version" of the WMI Class "Win32_ComputerSystemProduct" into the Variable "OSD_VariableName". This is for example usefully for Lenovo devices because the property holds the real model name (Lenovo Model Names) and not the cryptic ID which may change.

Other examples would be:

Device Disk Count:

powershell -Command "& {(New-Object -COMObject Microsoft.SMS.TSEnvironment).Value('OSD_DiskCount') = @(Get-WmiObject -query 'Select * from Win32_DiskDrive WHERE MediaType = \"Fixed hard disk media\"').Count}"

Device TPM Chip Available:

powershell -Command "& {(New-Object -COMObject Microsoft.SMS.TSEnvironment).Value('OSD_TPMChipAvailable') = [boolean](Get-WmiObject -Namespace 'ROOT\cimv2\Security\MicrosoftTpm' -query 'SELECT * FROM Win32_Tpm')}"

Event more complicated commands are possible but at some point a script provides more flexibility.

Important Note:

"Run Command Line" step in conjunction with "powershell -Command "& {Crazy-PowershellFunction}" has problems with double quotes ("). If they are required they need to be escaped with "\". See for example: Device Disk Count:

Other special characters my produce similar issues.

 

If you like this quick and simple solution and found some other useful commands please share them in a reply to this Topic

image.thumb.png.880c1dda5c83c2d45dce0355932f3b4a.png

Share this post


Link to post
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×