August 12th, 2008

Some WMI instances can have their first method call fail and get-member not work in PowerShell V1

PowerShell Team
PowerShell Team

Due to a problem retrieving the available methods in V1 that we have worked around for the upcoming version of PowerShell, you might experience that the first method call to a WMI object fails with a message that mentions:

           Exception calling GetType() with “0” argument(s): “You cannot call a method on a null-valued expression.”

 

This happens when calling the first method in objects that are not in the root\cimv2 like:

           $instance=([wmiclass]”root\MyNamespace:MyObject”).CreateInstance()

           $instance.GetType()

 

As a PowerShell V1 workaround, a first call to GetType() can be performed to prevent the failure in other method calls.

 

Also, the get-member cmdlet will fail to work with the instance above with the following error message:

           Get-Member : Exception retrieving members: “Not Found “

 

As a PowerShell V1 workaround, you can list the properties available in the object by calling:

         $instance.PsObject.Properties | format-table Name

 

We apologize for the inconvenience this might cause.

 

Lucio Silveira [MSFT]
Software Developer Engineer
Visit the Windows PowerShell Team blog at:   
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx 

Author

PowerShell Team
PowerShell Team

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

0 comments

Discussion are closed.