Registry Entries to Custom WMI class

i am hoping some one can help me with an issue that i am having. I am need to create a Custom WMI class in root/cmiv2 and add entries from the registry into to that custom class. Ideally i would like to have the code just to look at the regkey go though everything thats in it and add those entries to custom wmi class.

My code is:

$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

I tried the following code, but it did not work.

# Define the namespace and class name
$namespace = "rootcimv2"
$className = "OSDBuild"

# Define the class properties
$classProperties = @(
    New-CimProperty -Name "RegistryKeyName" -CimType String -Flags "Key, ReadOnly"
    New-CimProperty -Name "RegistryValueName" -CimType String -Flags "ReadOnly"
    New-CimProperty -Name "RegistryValueData" -CimType String -Flags "ReadOnly"
)

# Create the class
$class = New-CimClass -Namespace $namespace -ClassName $className -PropertyDefinition $classProperties

# Define the registry path and values
$registryPath = "HKLM:SOFTWAREOSDBuild"
$registryKey = "AdvertisementID"
$registryKey = "BuildRevision"
$registryKey = "Computername"
$registryKey = "Installation Type"
$registryKey = "InstallationDate"
$registryKey = "OrganisationName"
$registryKey = "OSDDuration"
$registryKey = "OSDStartTime"
$registryKey = "OSVersion"
$registryKey = "OSVersionName"
$registryKey = "Task Sequence Name"
$registryKey = "TaskSequenceID"
$registryValues = Get-ItemProperty -Path $registryPath

# Iterate through registry values and create instances of the custom class
foreach ($property in $registryValues.PSObject.Properties) {
    # Skip non-value properties
    if ($property.Name -eq "PSPath" -or $property.Name -eq "PSParentPath" -or $property.Name -eq "PSChildName" -or $property.Name -eq "PSDrive" -or $property.Name -eq "PSProvider") {
        continue
    }

    # Create an instance of the custom WMI class
    $instance = [PSCustomObject]@{
        RegistryKeyName    = $registryKey
        RegistryValueName  = $property.Name
        RegistryValueData  = $property.Value
    }

    # Convert to CimInstance
    $cimInstance = New-CimInstance -Namespace $namespace -ClassName $className -Property $instance

    # Save the instance to the WMI repository
    $cimInstance | New-CimInstance -Namespace $namespace

New contributor

user25512276 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật