Add Registry settings to custom WMI Class

Hello all, i really need your help with this one. I have registry settings that are being generated during SCCM OSD TS. I have been asked to add the same registry settings into custom wmi class. So i need to create class in root\cimv2 and call it OSDBuild and add entries into it. My entire powershell looks like this.

$RegKeyName = "OSDBuild"

# Set values
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$FullRegKeyName = "HKLM:\SOFTWARE\" + $regkeyname 

# Create Registry key
New-Item -Path $FullRegKeyName -type Directory -Force -ErrorAction SilentlyContinue

# Get values
$InstallTime = Get-Date -Format G 
$OSDStartTime = $tsenv.value("OSDStartTSTime")
$AdvertisementID = $tsenv.value("_SMSTSAdvertID")
$Organisation = $tsenv.value("_SMSTSOrgName")
$TaskSequenceID = $tsenv.value("_SMSTSPackageID")
$Packagename = $tsenv.value("_SMSTSPackageName")
$MachineName = $env:computername
$Installationmode = $tsenv.value("_SMSTSLaunchMode")
$BuildRevision = $tsenv.value("BuildRevision")
$OSName = $tsenv.vlaue("OSName")
$OSDDateUTC = (Get-Date).ToUniversalTime()

#Calculate time elapsed
$OSDTImeSpan = New-TimeSpan -start $OSDStartTime -end $InstallTime
$OSDDuration = "{0:hh}:{0:mm}:{0:ss}" -f $OSDTimeSpan

# Write values
new-itemProperty $FullRegKeyName -Name "InstalledDate" -value $InstallTime -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "OSDStartTime" -value $OSDStartTime -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty $FullRegKeyName -Name "OSDDuration" -value $OSDDuration -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "OrganisationName" -value $Organisation -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "AdvertisementID" -value $AdvertisementID -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "TaskSequenceID" -value $TaskSequenceID -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "Task Sequence Name" -value $Packagename -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "Installation Type" -value $Installationmode -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "Computername" -value $MachineName -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "OSVersion" -value (Get-CimInstance Win32_Operatingsystem).version -PropertyType String -Force | Out-Null
new-itemProperty $FullRegKeyName -Name "BuildRevision" -value $BuildRevision -Type STRING -Force -ErroAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "OSVersionName" -value $OSversionName -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null
new-itemProperty $FullRegKeyName -Name "OSDDateUTC" -value $OSDDateUTC -Type STRING -Force -ErrorAction SilentlyContinue | Out-Null

WMI classes are typically built with a MOF file or through a language like c++. I don’t know that there is dotNET method to create them. What exactly is the purpose for having a WMI class?

It would be so that I can inventory them later on with SCCM
Also, maybe I am not explaining it correctly. Maybe I need to create custom namespace in root/cimv2 and then add those reg entries to it.

You just have to install the SCCM agent on the client to accomplish that. :man_shrugging:t3:

… that’s usually done with a simple command line call like this:

\\<SCCM-Server-Name>\<SCCM-Site-Name>\Client\ccmsetup.exe

Its not that hard to inventory reg keys into CM. We do it for powershell and dotnet and sql versions. Google it and you will find plenty of examples to work from.

This is what I am trying to achieve. I just don’t know how to implement it into my script.

I think the point of the link you provided is to use “his” script. Have you tried that?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.