Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

meaning of this cast ?

Closed Thread
 
Thread Tools Display Modes
Old 11-15-2007   #1 (permalink)
Leo Tohill
Guest


 

meaning of this cast ?

About this line:

$wmi = [wmiclass]"\\.\ROOT\CIMV2:Win32_Service"

could someone explain to me the meaning of this? I know that it creates an
instance of wmiclass, but what PS language feature is in use?

Thanks,

Leo


My System SpecsSystem Spec
Old 11-15-2007   #2 (permalink)
Shay Levi
Guest


 

Re: meaning of this cast ?

Hi Leo

Check out the Windows PowerShell team blog, you'll find there various techniques
to get WMI objects and classes.

Improved Support for WMI
http://blogs.msdn.com/powershell/arc...26/647038.aspx


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> About this line:
>
> $wmi = [wmiclass]"\\.\ROOT\CIMV2:Win32_Service"
>
> could someone explain to me the meaning of this? I know that it
> creates an instance of wmiclass, but what PS language feature is in
> use?
>
> Thanks,
>
> Leo
>

My System SpecsSystem Spec
Old 11-15-2007   #3 (permalink)
Karl Prosser[MVP]
Guest


 

Re: meaning of this cast ?

first to type cast something in powershell you use the typename like this

[double]2

will return a double rather than just an integer.. however if also is
more than just typecasting you can convert such as

[int]"2"

basically the powershell engine will do whatever it can to try to
convert the object into the type specified.. but it goes ever further

certian classes have an ADAPTER, where the adapter has methods to try to
convert things into the object..

i.e
[xml] actually returns a dotnet xmldocument object..
so the adapter allows you to do a few things.. one is convert a string
into an xmldocument

$a = [xml] "<parent><child>something</child></parent>"

additionaly the adapter does other things, in the XML case.. an
XMldocument dotnet object has a set of static methods and properties,
however the adapter in powershell allows you to do

$a.parent.child

which of course is contextual to the contents of the xmldocument.. which
is really cool.

so in your case the wmiclass adapter converts a valid WMI path/query and
returns a dotnet system.management.managementobject .. the [ADSI]
adapter does likewise the an ldap path/query

alternatively you could have used the get-wmiobject cmdlet to do the
same thing

get-WmiObject win32_service -namespace "root/cimv2"

but the great thing about the adapter is you have alot of those WMI
strings hanging around in previous vbscripts or on the internet etc.

also the adapter in wmi is doing other great things, grabbing the
properties on each specific WMI class, and adapting to to the wmi
management object..

i.e

gwmi win32_service |Select-Object *
gwmi win32_process |Select-Object *

and you'll notice different properties specific to a service or a
process, even though the resulting object type is
system.management.managementobject each time.





Leo Tohill wrote:
Quote:

> About this line:
>
> $wmi = [wmiclass]"\\.\ROOT\CIMV2:Win32_Service"
>
> could someone explain to me the meaning of this? I know that it creates an
> instance of wmiclass, but what PS language feature is in use?
>
> Thanks,
>
> Leo
>
My System SpecsSystem Spec
Old 11-15-2007   #4 (permalink)
Leo Tohill
Guest


 

Re: meaning of this cast ?

very cool. Thanks.

"Karl Prosser[MVP]" wrote:
Quote:

> first to type cast something in powershell you use the typename like this
>
> [double]2
>
> will return a double rather than just an integer.. however if also is
> more than just typecasting you can convert such as
>
> [int]"2"
>
> basically the powershell engine will do whatever it can to try to
> convert the object into the type specified.. but it goes ever further
>
> certian classes have an ADAPTER, where the adapter has methods to try to
> convert things into the object..
>
> i.e
> [xml] actually returns a dotnet xmldocument object..
> so the adapter allows you to do a few things.. one is convert a string
> into an xmldocument
>
> $a = [xml] "<parent><child>something</child></parent>"
>
> additionaly the adapter does other things, in the XML case.. an
> XMldocument dotnet object has a set of static methods and properties,
> however the adapter in powershell allows you to do
>
> $a.parent.child
>
> which of course is contextual to the contents of the xmldocument.. which
> is really cool.
>
> so in your case the wmiclass adapter converts a valid WMI path/query and
> returns a dotnet system.management.managementobject .. the [ADSI]
> adapter does likewise the an ldap path/query
>
> alternatively you could have used the get-wmiobject cmdlet to do the
> same thing
>
> get-WmiObject win32_service -namespace "root/cimv2"
>
> but the great thing about the adapter is you have alot of those WMI
> strings hanging around in previous vbscripts or on the internet etc.
>
> also the adapter in wmi is doing other great things, grabbing the
> properties on each specific WMI class, and adapting to to the wmi
> management object..
>
> i.e
>
> gwmi win32_service |Select-Object *
> gwmi win32_process |Select-Object *
>
> and you'll notice different properties specific to a service or a
> process, even though the resulting object type is
> system.management.managementobject each time.
>
>
>
>
>
> Leo Tohill wrote:
Quote:

> > About this line:
> >
> > $wmi = [wmiclass]"\\.\ROOT\CIMV2:Win32_Service"
> >
> > could someone explain to me the meaning of this? I know that it creates an
> > instance of wmiclass, but what PS language feature is in use?
> >
> > Thanks,
> >
> > Leo
> >
> Very
My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
meaning of -eq $null Leo Tohill PowerShell 8 11-16-2007 06:53 PM
Colored groups, which meaning? Erhard Glueck Vista mail 1 09-04-2007 03:13 AM
Gives new meaning to air bags Adam Albright Vista General 5 08-10-2007 06:18 PM
OT: Vista meaning? John Vista General 11 06-21-2007 07:05 PM
What's the meaning of LOL? abcdefghijklmnopqrstuvwxyz Vista General 52 02-04-2007 05:57 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51