Windows Vista Forums

What goes with the WMI Win32_Share class
  1. #1


    Bob Landau Guest

    What goes with the WMI Win32_Share class

    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

      My System SpecsSystem Spec

  2. #2


    Kirk Munro Guest

    Re: What goes with the WMI Win32_Share class

    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" <BobLandau@xxxxxx> wrote in message
    news:50957105-D49F-4D59-A915-046B5BF57913@xxxxxx

    >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


      My System SpecsSystem Spec

  3. #3


    Bob Landau Guest

    Re: What goes with the WMI Win32_Share class

    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

    "Kirk Munro" wrote:

    > 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" <BobLandau@xxxxxx> wrote in message
    > news:50957105-D49F-4D59-A915-046B5BF57913@xxxxxx

    > >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
    >
    >
    >

      My System SpecsSystem Spec

What goes with the WMI Win32_Share class problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving from class C to class B ip address scheme, any tips(DC/DNS) markm75g Server General 1 14 Feb 2010
Urgent, Win32_Share is missing MG PowerShell 2 14 Dec 2009
When a class is both an inherited class of another, and alsoimplements an interface method Curious .NET General 1 14 Aug 2009
Subject: get-WMIObject win32_share - reinstall functionality pgw1959 PowerShell 0 17 Jun 2009
Win32_Share Clint Bodine PowerShell 2 11 May 2007