0

I'm trying to create a WMI class and populate it

I can't quite get my head around "Enumeration Available"

I know how to make InvalidExtensions enumerable but I don't understand how to populate this field when creating a WMI instance

I also don't understand how to prefill Possible Enumeration Values

My code so far

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

$newClass.Properties.Add("Username",[System.Management.CimType]::String, $false)
$newClass.Properties["Username"].Qualifiers.Add("Key", $true)

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

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

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

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

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

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

$newClass.Put()

Set-WmiInstance -Class Test -Argument @{Username="testaccount";TotalFileCount="5191";TotalFolderCount="355";TotalSizeMB="3660";InvalidFileNameCount="10";InvalidExtensionCount="2";InvalidExtensions=".appx",".ost"}

1 Answer 1

1

I worked out how to add the values

Changed

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

to

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

Then a standard array can be used when adding values

I still don't know how to set possible values in the class properties

Sign up to request clarification or add additional context in comments.

3 Comments

Just curious. But why do this in PowerShell? vs just using Visual Studio and the languages there and the specification. What is your use case?
Have an existing PowerShell script that does auditing, don't want to reinvent the wheel but need to make a new WMI class to store data to be collected by SCCM Long way of doing things I know
Hummm... yeppers, sure is a long way around the cart... not something I'd ever considered or tried.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.