Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What goes with the WMI Win32_Share class

483 views
Skip to first unread message

Bob Landau

unread,
Dec 20, 2007, 6:54:01 PM12/20/07
to
I am yet again confused as to how PowerShell displays the world. Specifically
I want to access the Create method

1) (Get-WmiObject -Class Win32_Share) | Get-Member # not reachable

2 ) (Get-WmiObject -Class Win32_Share) | Get-Member -static #the
ManagementObject class


3) [WmiClass] '\\.\Root\cimv2:Win32_share' | gm # reachable but whats the
difference?

4) (Get-WmiObject -List -ComputerName . | Where {$_.Name -eq
"Win32_Share"}) # again reachable but whats the difference in how this call
from 1) or 2)

I can't tell by looking at the doc's but I suspect this to be a static
method nevertheless adding the -static attribute to the Get-Member call
doesn't show it and

(Get-WmiObject -Class Win32_Share) :: Create(....) doesn't work non-existant
method

I am able to create shares using

([WmiClass] '\\.\Root\cimv2:Win32_share' ).Create(...)

But I at a lost to understand what's the difference and more importantly
when should you use

Get-WmiObject -Class ....

and when should you use

[WmiClass] '......'

thx

bob

Kirk Munro

unread,
Dec 20, 2007, 10:10:04 PM12/20/07
to
Hi Bob,

I've been working with Get-WmiObject a lot the past week or so and had some
of these same challenges. Fortunately I think I've got a good grasp on it
now so I'll try and help you out here.

When you call Get-WmiObject without the -List parameter, you're retrieving
instances of WMI objects on a particular computer. In the case of the
Win32_Share class, you're retrieving actual shares on the specified
computer. In contrast, if you use the -List parameter you're retrieving
actual WMI classes. This is why you get different members for the two
object types. The Create method is available for the Win32_Share class
object, but if you have an instance of a Win32_Share, such as C$, the create
method isn't available because you're dealing with an object, not a WMI
class.

Further, when you cast a WMI path to [WmiClass], you're retrieving the
actual WMI class object so that you can then use it to do things like create
shares. You could also case the same sort of path to
[System.Management.ManagementClass] and you would get the same results.

Similarly, if you cast a WMI object path to
[System.Management.ManagementObject] you will get the actual WMI instance
representing that object. If you're using a path to a physical share, it
cannot be used to create shares because share objects weren't designed so
that they could create other shares, but the Win32_Share class was.

Your third example and your fourth example return the same objects, but the
third example does so much more efficiently because it doesn't have to
retrieve all classes and then filter out all but the one you want.

A picture is always worth a thousand words, so take a look at the types
returned in this transcript snippet and you'll see what I mean by all of
this:

PS C:\> Get-WmiObject -Class Win32_Share | Where-Object { $_.Name -eq 'C$' }
| Invoke-Member PSObject.TypeNames
System.Management.ManagementObject#root\cimv2\Win32_Share
System.Management.ManagementObject
System.Management.ManagementBaseObject
System.ComponentModel.Component
System.MarshalByRefObject
System.Object

PS C:\>
[System.Management.ManagementObject]'\\.\root\cimv2:Win32_Share.Name="C$"' |
Invoke-Member PSObject.TypeNames
System.Management.ManagementObject#root\cimv2\Win32_Share
System.Management.ManagementObject
System.Management.ManagementBaseObject
System.ComponentModel.Component
System.MarshalByRefObject
System.Object

PS C:\> Get-WmiObject -List -ComputerName . | Where-Object { $_.Name -eq
'Win32_Share' } | Invoke-Member PSObject.TypeNames
System.Management.ManagementClass#ROOT\cimv2\Win32_Share
System.Management.ManagementClass
System.Management.ManagementObject
System.Management.ManagementBaseObject
System.ComponentModel.Component
System.MarshalByRefObject
System.Object

PS C:\> [WmiClass]'\\.\Root\cimv2:Win32_Share' | Invoke-Member
PSObject.TypeNames
System.Management.ManagementClass#ROOT\cimv2\Win32_Share
System.Management.ManagementClass
System.Management.ManagementObject
System.Management.ManagementBaseObject
System.ComponentModel.Component
System.MarshalByRefObject
System.Object

PS C:\> [System.Management.ManagementClass]'\\.\root\cimv2:Win32_Share' |
Invoke-Member PSObject.TypeNames
System.Management.ManagementClass#ROOT\cimv2\Win32_Share
System.Management.ManagementClass
System.Management.ManagementObject
System.Management.ManagementBaseObject
System.ComponentModel.Component
System.MarshalByRefObject
System.Object

In these examples, the first two objects retrieved are identical and they
have the same types, and the last three objects retrieved (which are
actually classes) are identical and they have the same types.

Does that help?

--
Kirk Munro
Poshoholic
http://poshoholic.com


"Bob Landau" <BobL...@discussions.microsoft.com> wrote in message
news:50957105-D49F-4D59...@microsoft.com...

Bob Landau

unread,
Dec 21, 2007, 2:33:01 PM12/21/07
to
Ah yes,

I should have looked more closely. Next time I need to create a "blob" using
WMI I'll closely to see if it is factored the "Create" members into a class
type.

Thanks for the help
bob

0 new messages