{"id":5601,"date":"2008-08-12T16:50:00","date_gmt":"2008-08-12T16:50:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/08\/12\/some-wmi-instances-can-have-their-first-method-call-fail-and-get-member-not-work-in-powershell-v1\/"},"modified":"2019-02-18T13:13:04","modified_gmt":"2019-02-18T20:13:04","slug":"some-wmi-instances-can-have-their-first-method-call-fail-and-get-member-not-work-in-powershell-v1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/some-wmi-instances-can-have-their-first-method-call-fail-and-get-member-not-work-in-powershell-v1\/","title":{"rendered":"Some WMI instances can have their first method call fail and get-member not work in PowerShell V1"},"content":{"rendered":"<p><span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">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: <\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exception calling GetType() with \u201c0\u201d argument(s): \u201cYou cannot call a method on a null-valued expression.\u201d<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><\/font><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">This happens when calling the first method in objects that are not in the root\\cimv2 like:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><span>&nbsp;<\/span><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$instance=([wmiclass]&#8221;root\\MyNamespace:MyObject&#8221;).CreateInstance()<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><b><i><span lang=\"EN\"><span>&nbsp;<\/span><\/span><\/i><\/b><span lang=\"EN\"><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span lang=\"EN\"><font color=\"#000000\">$instance.GetType()<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><\/font><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">As a PowerShell V1 workaround, a first call to GetType() can be performed to prevent the failure in other method calls.<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><\/font><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">Also, the get-member cmdlet will fail to work with the instance above with the following error message:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-Member : Exception retrieving members: \u201cNot Found \u201c<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><\/font><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">As a PowerShell V1 workaround, you can list the properties available in the object by calling:<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span lang=\"EN\"><font color=\"#000000\">$instance.PsObject.Properties | format-table Name<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><\/font><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">We apologize for the inconvenience this might cause.<\/font><\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\"><\/font><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\"><font color=\"#000000\">Lucio Silveira&nbsp;[MSFT]<br \/>Software Developer Engineer<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <\/font><\/span><span><a href=\"http:\/\/blogs.msdn.com\/PowerShell\"><strong><span>http:\/\/blogs.msdn.com\/PowerShell<\/span><\/strong><\/a><br \/><\/span><span lang=\"EN\"><font color=\"#000000\">Visit the Windows PowerShell ScriptCenter at:&nbsp; <\/font><\/span><span><a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\"><strong><span>http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/span><\/strong><\/a>&nbsp;<\/span><span lang=\"EN\"><\/span><\/p>\n<p class=\"MsoNormal\"><\/span><span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exception calling GetType() with \u201c0\u201d argument(s): \u201cYou cannot call a method on a null-valued expression.\u201d [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[248,26],"class_list":["post-5601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>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: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exception calling GetType() with \u201c0\u201d argument(s): \u201cYou cannot call a method on a null-valued expression.\u201d [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/5601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=5601"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/5601\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=5601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=5601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=5601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}