Jump to content


  • 0
jHetzer

OSD Run Command Line: WMI to TS Variable

Question

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

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.

E.g. 

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

image.png.0e263c6f71cdc7a8115f6e921833c0bd.png

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

image.png.6498554ca6f956599d0deef8bea9e846.png

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.

Guest
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.

Loading...


×
×
  • 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.