Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Powershell and .Net Object

Reply
 
Old 01-22-2007   #1 (permalink)
Nitin


 
 

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 SpecsSystem Spec
Old 01-22-2007   #2 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

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 SpecsSystem Spec
Old 01-22-2007   #3 (permalink)
Adam Geras


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums 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 Ltd

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