"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