1

using WMI with PowerShell I found something I don't understand:

# Syntax 1
gwmi -Class Win32_Share | gm -MemberType Method
Output: Delete, GetAccessMask, SetShareInfo

# Syntax 2
$a = New-Object "System.Management.ManagementClass" "Win32_Share" :
$a | gm -MemberType Method
Output: Create.....

So: why I don't get the "Create" Method using the syntax "1"?

1 Answer 1

3

Because they return two different types of objects.

(gwmi -Class Win32_Share).GetType()

returns a System.Array instance while

(New-Object "System.Management.ManagementClass" "Win32_Share").GetType()

returns a System.Management.ManagementObject instance

Note that it doesn't make sense to call Create on an already instantiated object anyway, or in other words: why do you think you need it?

Edit

Your comment actually made me rethink (finally) and your conondrum is that you should use -query instead of -class. I have yet to figure out what the actual difference between both methods of calling is but I assume it's the same class/instance distinction.

Get-WmiObject -query "SELECT * FROM meta_class WHERE __class = 'Win32_Share'"
2
  • 1
    Hi Lieven, thanks for help. In this case (maybe it's somehow too academic..) the method "create" makes sense since it doesn't create an object itself, but a new share.
    – Purclot
    Commented Sep 27, 2016 at 19:06
  • @Purclot - I have updated the answer to adress your comment. fwiw - using the WMI commandlets is being discouraged in favour of the CIM commandlets. Commented Sep 28, 2016 at 5:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.