Jump to content

  • 0

OSD Run Command Line: WMI to TS Variable


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


Share this post

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi Bro,

    It's really a nice post, thanks for your contributions and I have another question: How can I monitor the value of the task sequence that I created and write to the log.


MDT : 6.3.8456.1000 installed on Windows Server 2012 R2

Client: HP Laptop with dual hard disk. Disk 0: SSD 256G, Disk 1:  HDD 500G

Aim:  Install the OS on SSD (No all the SSD is on Disk 0, so I want to dynamic select )

I follow your post and create a variable that named OSD_DiskType.

powershell -Command "& {(New-Object -COMObject Microsoft.SMS.TSEnvironment).Value('OSD_DiskType') = (Get-Physicaldisk).MediaType}"

I can find it run and exist code is 0 in smsts.log


But the TS doesn't work as I defined during the disk format and partition


Log:  The action (Format and Partition Disk (UEFI) Disk0) has been skipped because the condition is evaluated to be false

Question: How can I output the queried information to the log so that I know what happened and find the root of the issue.


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.