urkec
2008-03-06 17:43:01 UTC
How can I convert this C# code to PowerShell:
static void Main()
{
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
ManagementClass newClass =
new ManagementClass(
"root/default",
String.Empty,
null);
newClass["__Class"] = "MyClass";
newClass.Put(options);
}
The code creates an empty WMI class , names it 'MyClass' and saves it in
root\default namespace. This is what I have tried:
$options = New-Object System.Management.PutOptions;
$options.Type = [System.Management.PutType]::CreateOnly;
$newclass = New-Object System.Management.ManagementClass ("root\default",
[String]::Empty, $null);
$newclass["__CLASS"] = "MyClass";
$newclass.Put($options);
but I get this error:
Exception calling "Put" with "1" argument(s): "You cannot call a method on a
null-valued expression."
At line 5, position 14
$newclass.Put($options);
Thanks.
static void Main()
{
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
ManagementClass newClass =
new ManagementClass(
"root/default",
String.Empty,
null);
newClass["__Class"] = "MyClass";
newClass.Put(options);
}
The code creates an empty WMI class , names it 'MyClass' and saves it in
root\default namespace. This is what I have tried:
$options = New-Object System.Management.PutOptions;
$options.Type = [System.Management.PutType]::CreateOnly;
$newclass = New-Object System.Management.ManagementClass ("root\default",
[String]::Empty, $null);
$newclass["__CLASS"] = "MyClass";
$newclass.Put($options);
but I get this error:
Exception calling "Put" with "1" argument(s): "You cannot call a method on a
null-valued expression."
At line 5, position 14
$newclass.Put($options);
Thanks.
--
urkec
urkec