"RichS" wrote:
> I must admit that I'm not 100% sure what you are trying to achieve from your
> question but if you want to create a new instance of a class in WMI in
> PowerShell V1 the normal way to do it is
>
> $w = [WMIClass]"\\.\root\cimv2:Win32_Process"
> $w.Create("Notepad.exe")
>
> Can you post an example of what you are trying to do and which class you are
> using. It can be in VBScript if necessary.
> > I am trying to create a new join view class in WMI. I need to create an empty
> > class, set it's properties and qualifiers and save it to the repository. I am trying to create WMI join view classes. I managed to register the view
provider, but I can't figure out how to create a new class (not an instance
of an existing class). Basically I want to replicate a MOF like this one with
PowerShell:
[JoinOn("Win32_DiskPartition.DiskIndex = Win32_DiskDrive.Index"),
ViewSources{"SELECT DiskIndex, Index, DeviceID FROM Win32_DiskPartition" ,
"SELECT Index, Caption, Model FROM Win32_DiskDrive"},
ViewSpaces{"\\\\.\\root\\cimv2", "\\\\.\\root\\cimv2"},
dynamic: ToInstance, provider("MS_VIEW_INSTANCE_PROVIDER")]
class PrinterPropsd
{
[PropertySources{"DiskIndex", "Index"}] UInt32 ID;
[PropertySources{"", "Caption"}] String Caption;
[PropertySources{"Index", ""}, key] Uint32 Index;
[PropertySources{"DeviceID", ""}] String DeviceId;
[PropertySources{"", "Model"}] String Model;
};
In VBScript I would get the SWbemServices object and use it's Get method to
get an empty SWBemObject, make it a class with properties and qualifiers like
above and save it to the repository as a new class. This is the part of WMI
SDK where I found this:
http://msdn2.microsoft.com/en-us/lib...65(VS.85).aspx
This is the sample join view class:
http://msdn2.microsoft.com/en-us/lib...54(VS.85).aspx
This is how a new class is created with VBScript
:
set NewObject = GetObject("winmgmts:root\default").Get
NewObject.Path_.Class = "Test"
NewObject.Properties_.Add "A", wbemCimtypeString
I tried Darren's suggestion and it didn't error out on the second line
$ViewClass = New-Object System.Management.ManagementClass
$ViewClass.PSBase.ClassPath.ClassName = "Test"
$ViewClass.PSBase.GetType()
$ViewClass.PSBase.Properties.Add("A", "A")
$ViewClass.PSBase.Put()
but when I try to use Put method I get "Invalid operation" error.
Thanks.
--
urkec