Windows Vista Forums

WMIClass
  1. #1


    TimN Guest

    WMIClass

    I am trying to convert the following vbscript to powershell and I seem to be
    having alittle bit of difficulty.

    Set Service =
    GetObject("winmgmts:{impersonationlevel=impersonate}!<namespace>)
    Set instCollection = Services.Get(<class name>).SpawnInstance_

    Are any of the following equivalent:

    $Object = [wmiclass]"<namespace>:<class name>"

    - or -

    $object = ([wmiclass]"<namespace>:<class name>").CreateInstance


    when I use the vbscript version of the code after I populate the required
    paramters and execute the "Put_" method, additional properties are populated.
    When I use either powershell command that I listed above nothing changes
    after populating the parameters via the $object.PSBase.Item(<property name>)
    syntax and calling $object.PSBase.Put() method.



    I am kinda new to WMI scripting and powershell in general so any information
    that you can provide will be greatly appriciated

    TiA

    TimN


      My System SpecsSystem Spec

  2. #2


    RichS [MVP] Guest

    RE: WMIClass

    This might help

    Creating a WMI class

    --
    Richard Siddaway
    All scripts are supplied "as is" and with no warranty
    PowerShell MVP
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "TimN" wrote:

    > I am trying to convert the following vbscript to powershell and I seem to be
    > having alittle bit of difficulty.
    >
    > Set Service =
    > GetObject("winmgmts:{impersonationlevel=impersonate}!<namespace>)
    > Set instCollection = Services.Get(<class name>).SpawnInstance_
    >
    > Are any of the following equivalent:
    >
    > $Object = [wmiclass]"<namespace>:<class name>"
    >
    > - or -
    >
    > $object = ([wmiclass]"<namespace>:<class name>").CreateInstance
    >
    >
    > when I use the vbscript version of the code after I populate the required
    > paramters and execute the "Put_" method, additional properties are populated.
    > When I use either powershell command that I listed above nothing changes
    > after populating the parameters via the $object.PSBase.Item(<property name>)
    > syntax and calling $object.PSBase.Put() method.
    >
    > I am kinda new to WMI scripting and powershell in general so any information
    > that you can provide will be greatly appriciated
    >
    > TiA
    >
    > TimN
    >

      My System SpecsSystem Spec

  3. #3


    TimN Guest

    RE: WMIClass

    Thanks for the tip....I will try this out when I get to my lab environment
    later on tonight

    "RichS [MVP]" wrote:

    > This might help
    >
    > Creating a WMI class
    >
    > --
    > Richard Siddaway
    > All scripts are supplied "as is" and with no warranty
    > PowerShell MVP
    > Blog: http://richardsiddaway.spaces.live.com/
    > PowerShell User Group: http://www.get-psuguk.org.uk
    >
    >
    > "TimN" wrote:
    >

    > > I am trying to convert the following vbscript to powershell and I seem to be
    > > having alittle bit of difficulty.
    > >
    > > Set Service =
    > > GetObject("winmgmts:{impersonationlevel=impersonate}!<namespace>)
    > > Set instCollection = Services.Get(<class name>).SpawnInstance_
    > >
    > > Are any of the following equivalent:
    > >
    > > $Object = [wmiclass]"<namespace>:<class name>"
    > >
    > > - or -
    > >
    > > $object = ([wmiclass]"<namespace>:<class name>").CreateInstance
    > >
    > >
    > > when I use the vbscript version of the code after I populate the required
    > > paramters and execute the "Put_" method, additional properties are populated.
    > > When I use either powershell command that I listed above nothing changes
    > > after populating the parameters via the $object.PSBase.Item(<property name>)
    > > syntax and calling $object.PSBase.Put() method.
    > >
    > > I am kinda new to WMI scripting and powershell in general so any information
    > > that you can provide will be greatly appriciated
    > >
    > > TiA
    > >
    > > TimN
    > >

      My System SpecsSystem Spec

  4. #4


    urkec Guest

    RE: WMIClass

    "TimN" wrote:

    > Thanks for the tip....I will try this out when I get to my lab environment
    > later on tonight
    >
    > "RichS [MVP]" wrote:
    >

    > > This might help
    > >
    > > Creating a WMI class
    > >
    > > --
    > > Richard Siddaway
    > > All scripts are supplied "as is" and with no warranty
    > > PowerShell MVP
    > > Blog: http://richardsiddaway.spaces.live.com/
    > > PowerShell User Group: http://www.get-psuguk.org.uk
    > >
    > >
    > > "TimN" wrote:
    > >

    > > > I am trying to convert the following vbscript to powershell and I seem to be
    > > > having alittle bit of difficulty.
    > > >
    > > > Set Service =
    > > > GetObject("winmgmts:{impersonationlevel=impersonate}!<namespace>)
    > > > Set instCollection = Services.Get(<class name>).SpawnInstance_
    > > >
    > > > Are any of the following equivalent:
    > > >
    > > > $Object = [wmiclass]"<namespace>:<class name>"
    > > >
    > > > - or -
    > > >
    > > > $object = ([wmiclass]"<namespace>:<class name>").CreateInstance
    > > >
    > > >
    > > > when I use the vbscript version of the code after I populate the required
    > > > paramters and execute the "Put_" method, additional properties are populated.
    > > > When I use either powershell command that I listed above nothing changes
    > > > after populating the parameters via the $object.PSBase.Item(<property name>)
    > > > syntax and calling $object.PSBase.Put() method.
    > > >
    > > > I am kinda new to WMI scripting and powershell in general so any information
    > > > that you can provide will be greatly appriciated
    > > >
    > > > TiA
    > > >
    > > > TimN
    > > >

    CreateInstance() works for me:


    $object = ([wmiclass]"Win32_Environment").CreateInstance()
    $object.UserName = [System.Environment]::UserName
    $object.Name = "TestVar"
    $object.VariableValue = "Test Environment Variable"
    $object.Put()



    --
    urkec

      My System SpecsSystem Spec

  5. #5


    TimN Guest

    RE: WMIClass

    I guess being overworked is starting to get to me. After retesting
    CreateInstance did work as well as using ManagementObject.

    Thanks again for the help

    "urkec" wrote:

    > "TimN" wrote:
    >

    > > Thanks for the tip....I will try this out when I get to my lab environment
    > > later on tonight
    > >
    > > "RichS [MVP]" wrote:
    > >

    > > > This might help
    > > >
    > > > Creating a WMI class
    > > >
    > > > --
    > > > Richard Siddaway
    > > > All scripts are supplied "as is" and with no warranty
    > > > PowerShell MVP
    > > > Blog: http://richardsiddaway.spaces.live.com/
    > > > PowerShell User Group: http://www.get-psuguk.org.uk
    > > >
    > > >
    > > > "TimN" wrote:
    > > >
    > > > > I am trying to convert the following vbscript to powershell and I seem to be
    > > > > having alittle bit of difficulty.
    > > > >
    > > > > Set Service =
    > > > > GetObject("winmgmts:{impersonationlevel=impersonate}!<namespace>)
    > > > > Set instCollection = Services.Get(<class name>).SpawnInstance_
    > > > >
    > > > > Are any of the following equivalent:
    > > > >
    > > > > $Object = [wmiclass]"<namespace>:<class name>"
    > > > >
    > > > > - or -
    > > > >
    > > > > $object = ([wmiclass]"<namespace>:<class name>").CreateInstance
    > > > >
    > > > >
    > > > > when I use the vbscript version of the code after I populate the required
    > > > > paramters and execute the "Put_" method, additional properties are populated.
    > > > > When I use either powershell command that I listed above nothing changes
    > > > > after populating the parameters via the $object.PSBase.Item(<property name>)
    > > > > syntax and calling $object.PSBase.Put() method.
    > > > >
    > > > > I am kinda new to WMI scripting and powershell in general so any information
    > > > > that you can provide will be greatly appriciated
    > > > >
    > > > > TiA
    > > > >
    > > > > TimN
    > > > >
    >
    >
    > CreateInstance() works for me:
    >
    >
    > $object = ([wmiclass]"Win32_Environment").CreateInstance()
    > $object.UserName = [System.Environment]::UserName
    > $object.Name = "TestVar"
    > $object.VariableValue = "Test Environment Variable"
    > $object.Put()
    >
    >
    >
    > --
    > urkec

      My System SpecsSystem Spec

WMIClass problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
WMIClass again! DungKHoang PowerShell 2 06 May 2008
[WMIClass] versus get-wmiobject Hal Rottenberg PowerShell 9 03 Jul 2007