Monday, 25 November 2024

Tattoo Task Sequence Data in WMI

Introduction

In the OS provisioning build world we do like to stamp a newly built device with some information.  This may be the task sequence name and the build version as well as other useful information.  And it is common to place this information in the registry and collect it with MECM by extending the hardware inventory collection data.  With my latest project I decided to write this information to the WMI repository using a PowerShell script.  One advantage of branding in this way is that extending the Hardware Inventory is much easier. 

In addition, I decided to include data that would be useful for troubleshooting issues.  For instance, by including the models supported by the task sequence, a helpdesk technician can easily determine if an incorrect Task Sequence had been deployed to the device when viewing the data in the Resource Explorer in MECM.

There are three steps required to complete this task

1) Populate the PowerShell script with the data to be collected.

2) Create a Task Sequence step to run the PowerShell script.

3) Extend the MECM hardware inventory classes to collect this information from the provisioned device.

Populate the PowerShell script with the data to be collected

The first part of the PowerShell script is the VARIABLE DECLARATION section.  Fill it in as required.  The $WMIClassName variable defines the name of the class under which the instance, containing the data, will be created.  This name should remain the same whenever you update the build task sequence.


#VARIABLE DECLARATION

$WMIClassName="BuildInfo"

$BuildVersion="1.0"

$ProjectName="ENHANCEMENT"

$TSName="Install Windows 10 22H2"

$SupportedModels="HP Pro SFF 400 G9,Lifebook u7410"

$ChangesMade="Removed Internet Explorer.  Added drivers for HP Pr SFF 400 G9.  Removed Windows Store App"


The second part of the script creates the WMI class.  The third part of the script deletes any instances under the class name, if they exist, and then creates the instance with the information as defined in the VARIABLE DECLARATION section.  Here is the script complete with the above information defined.


#VARIABLE DECLARATION

$WMIClassName="BuildInfo"

$BuildVersion="1.0"

$ProjectName="ENHANCEMENT"

$TSName="Install Windows 10 22H2"

$SupportedModels="HP Pro SFF 400 G9,Lifebook u7410"

$ChangesMade="Removed Internet Explorer.  Added drivers for HP Pr SFF 400 G9.  Removed Windows Store App"


#CREATE THE WMI CLASS

$newClass = New-Object System.Management.ManagementClass("root\cimv2", [String]::Empty, $null); 

$newClass["__CLASS"] = $WMIClassName; 

$newClass.Qualifiers.Add("Static", $true)

$newClass.Properties.Add("BuildVersion",[System.Management.CimType]::String, $false)

$newClass.Properties["BuildVersion"].Qualifiers.Add("Key", $true)

$newClass.Properties.Add("ProjectName",[System.Management.CimType]::String, $false)

$newClass.Properties.Add("TSName",[System.Management.CimType]::String, $false)

$newClass.Properties.Add("SupportedModels",[System.Management.CimType]::String, $false)

$newClass.Properties.Add("ChangesMade",[System.Management.CimType]::String, $false)

$newClass.Properties.Add("InvalidExtensions",[System.Management.CimType]::String, $false)

#$newClass.Properties["InvalidExtensions"].Qualifiers.Add("Values",$true)

$newClass.Put()


#REMOVE EXISTING INSTANCES

$Inst=get-wmiobject -query "select * from $WMIClassName"

$Inst|remove-wmiobject


#CREATE THE NEW INSTANCE

set-wmiinstance -Class $WMIClassName -Arguments @{BuildVersion="$BuildVersion";ProjectName="$ProjectName";TSName="$TSName";SupportedModels="$SupportedModels";ChangesMade="$ChangesMade"}

This script should be tested on a device to ensure the class is created and the instance is populated.  Test it on a device that also has the MECM console installed.


After the script is run, type in wbemtest.  Click on Connect and then Connect again.  Click on Query and type select * from <name of class>.  In this case it would be select * from BuildInfo.


Click on Apply and then double click on the BuildInfo.BuildVersion instance.  Ensure that all the data is filled in as expected.


Create a Task Sequence step to run the PowerShell script

Open the MECM console and navigate to Software Library\Overview\Operating Systems\Task sequences.

Right Click on your task sequence and click Edit.  Click on a step after the Setup Windows and Configuration Manager step in the Setup Operating System group.  From the top click on Add and then General and then Run PowerShell Script.  Enter in a name such as Create Build Tattoo.  Click on the Enter a PowerShell script option and then select Add Script .  Paste the script into the script area.


Click on Ok.  Ensure that the correct PowerShell execution policy level is selected and then click on OK again.

Extend the MECM hardware inventory classes

Firstly, as suggested above, you should run the script on a device with the MECM console installed.  This will create your WMI class along with an instance containing the data.  This data will be reported back to the MECM database when the Hardware Inventory cycle completes on your device.

Open the MECM console and navigate to  Administration\Overview\Client SettingsRight click and select Properties on the required Client Settings object in the right hand pane.  In this example we use the Default Client Settings object.

The Client Settings window appears.



Click on Set Classes.  The Hardware Inventory Classes window appears.


Click on Add and then Connect and then Connect again.  The Add Hardware Inventory Classes window appears.  Locate your newly created class and select your newly created class.  Click on OK


The Hardware Inventory Classes window reappears.  Select your newly created class and deselect the Invalid Extensions property.

Click on OK and then OK again.


You can now use Resource Explorer, within MECM, to view the build details pertaining to the device. This will appear after the next hardware inventory cycle completes on your clients.



Conclusion

The build tattoo is often overlooked but is really essential.  It is vital for ensuring that you can bring all your built devices to the same level.  If support orientated data is included, such as supported models, it can be of great assistance to the helpdesk.  I hope you have enjoyed reading this article and I wish you every success in developing your own build versioning tattoo in your environment.









Tattoo Task Sequence Data in WMI

Introduction In the OS provisioning build world we do like to stamp a newly built device with some information.  This may be the task sequen...