![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| The Meaning of Valentine's Day | Chillout Room | |||
| meaning of -eq $null | PowerShell | |||
| Gives new meaning to air bags | Vista General | |||
| OT: Vista meaning? | Vista General | |||
| What's the meaning of LOL? | Vista General | |||