![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Powershell and .Net Object Hi there, Looks like from Powershell we cannot call the the public methods exposed by a .Net Class. For example, System.Management.ManagementClass class has a public method "GetInstances()". We can call it from C# code but not from Powershell PS > $mo = Get-WmiObject -class Win32_OperatingSystem PS > $mo.GetIintances() Method invocation failed because [System.Management.ManagementObject#root\cimv2\Win32_OperatingSystem] doesn't contain a method named 'GetIintances'. At line:1 char:17 + $mo.GetIintances( <<<< ) Any Idea how poweshell determines which methods are available? I used to think, it just uses .Net reflect to find out the available methods but if i run $mo | Get-Member I don't see all the public methods exposed by System.Management.ManagementClass thx, Nitin |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Powershell and .Net Object as PowerShell uses a wrapper for WMI access You need to use PsBase to get to the base Object $mo.PsBase.GetIinstances() Also I made a 3 part series (more still to come on my new blog) on my old blog about the WMI wrapper : http://mow001.blogspot.com/2006/10/p...c2-series.html http://mow001.blogspot.com/2006/10/p...series_02.html http://mow001.blogspot.com/2006/10/p...rt-in-rc2.html Greetings /\/\o\/\/ http://thePowerShellGuy.com "Nitin" <Nitin@discussions.microsoft.com> wrote in message news:228AC0D8-6B54-4071-99DC-DE4441A56998@microsoft.com... > Hi there, > > Looks like from Powershell we cannot call the the public methods exposed > by > a .Net Class. For example, System.Management.ManagementClass class has a > public method "GetInstances()". We can call it from C# code but not from > Powershell > > PS > $mo = Get-WmiObject -class Win32_OperatingSystem > PS > $mo.GetIintances() > Method invocation failed because > [System.Management.ManagementObject#root\cimv2\Win32_OperatingSystem] > doesn't > contain > a method named 'GetIintances'. > At line:1 char:17 > + $mo.GetIintances( <<<< ) > > Any Idea how poweshell determines which methods are available? I used to > think, it just uses .Net reflect to find out the available methods but if > i > run > $mo | Get-Member > > I don't see all the public methods exposed by > System.Management.ManagementClass > > > thx, > Nitin > |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Powershell and .Net Object I see a typo $mo.GetIintances() "Nitin" wrote: > Hi there, > > Looks like from Powershell we cannot call the the public methods exposed by > a .Net Class. For example, System.Management.ManagementClass class has a > public method "GetInstances()". We can call it from C# code but not from > Powershell > > PS > $mo = Get-WmiObject -class Win32_OperatingSystem > PS > $mo.GetIintances() > Method invocation failed because > [System.Management.ManagementObject#root\cimv2\Win32_OperatingSystem] doesn't > contain > a method named 'GetIintances'. > At line:1 char:17 > + $mo.GetIintances( <<<< ) > > Any Idea how poweshell determines which methods are available? I used to > think, it just uses .Net reflect to find out the available methods but if i > run > $mo | Get-Member > > I don't see all the public methods exposed by > System.Management.ManagementClass > > > thx, > Nitin > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| powershell new-object errror | PowerShell | |||
| Creating XPathDocument object in Powershell | PowerShell | |||
| Powershell Object Reference | PowerShell | |||
| RE: Getting Deleted Object info with Powershell | PowerShell | |||
| RE: Howto: Use a com object in Powershell | PowerShell | |||