![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) | ||||||||||||
| 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
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| 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:
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||
| Guest | Re: meaning of this cast ? very cool. Thanks. "Karl Prosser[MVP]" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
![]() |
| 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 |