Forum Discussion
SCCMnube78
Jun 07, 2024Copper Contributor
Add Entries to WMI
Hello all, i am urgently looking for help from you guys. I have this script with entries that are being written to the registry. I am looking for a way to write the same entries into custom WMI class...
sdtslmn
Jul 24, 2024Brass Contributor
hope the following additions can help you
$RegKeyName = "OSDBuild"
$WMIClassName = "OSDBuildInfo" # Choose a suitable name for your WMI class
# Set values
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$FullRegKeyName = "HKLM:\SOFTWARE\" + $regkeyname
# ... (Your existing code for getting values remains the same) ...
# Write values to WMI
try {
$wmiNamespace = Get-WmiObject -Namespace root\cimv2 -Class __Namespace
if (-not ($wmiNamespace | Where-Object {$_.Name -eq $WMIClassName})) {
# Create the custom WMI class if it doesn't exist
$wmiClass = $wmiNamespace.CreateClass($WMIClassName, "Win32_OperatingSystem", $null)
} else {
$wmiClass = Get-WmiObject -Namespace root\cimv2 -Class $WMIClassName
}
$wmiInstance = $wmiClass.CreateInstance()
# Set WMI instance properties (same as registry values)
$wmiInstance.InstalledDate = $InstallTime
$wmiInstance.OSDStartTime = $OSDStartTime
$wmiInstance.OSDDuration = $OSDDuration
$wmiInstance.OrganisationName = $Organisation
$wmiInstance.AdvertisementID = $AdvertisementID
$wmiInstance.TaskSequenceID = $TaskSequenceID
$wmiInstance.TaskSequenceName = $Packagename
$wmiInstance.InstallationType = $Installationmode
$wmiInstance.Computername = $MachineName
$wmiInstance.OSVersion = (Get-CimInstance Win32_Operatingsystem).version
# Commit the changes to the WMI repository
$wmiInstance.Put()
} catch {
Write-Error "Failed to write WMI data: $_"
}