Windows Vista Forums
Vista Forums Home Join Vista Forums Donate 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

invoking .net classes in powershell

Closed Thread
 
Thread Tools Display Modes
Old 01-03-2007   #1 (permalink)
Jim B
Guest


 

invoking .net classes in powershell

I am trying to figure out why these lines work:

PS C:\> $test = [system.net.webrequest]
PS C:\> $test2 = [system.net.webclient]

and this one generares an error:

PS C:\> $testftp = [System.Net.WebRequestMethods.Ftp]
Unable to find type [System.Net.WebRequestMethods.Ftp]: make sure that
the assembly containing this type is loaded.
At line:1 char:45
+ $testftp = [System.Net.WebRequestMethods.Ftp] <<<<

Old 01-03-2007   #2 (permalink)
/\/\o\/\/ [MVP]
Guest


 

RE: invoking .net classes in powershell

$WC = NEW-OBJECT System.Net.WebClienT
$wc
$wc | gm


"Jim B" wrote:

> I am trying to figure out why these lines work:
>
> PS C:\> $test = [system.net.webrequest]
> PS C:\> $test2 = [system.net.webclient]
>
> and this one generares an error:
>
> PS C:\> $testftp = [System.Net.WebRequestMethods.Ftp]
> Unable to find type [System.Net.WebRequestMethods.Ftp]: make sure that
> the assembly containing this type is loaded.
> At line:1 char:45
> + $testftp = [System.Net.WebRequestMethods.Ftp] <<<<
>
>

Old 01-03-2007   #3 (permalink)
Jacques Barathon [MS]
Guest


 

Re: invoking .net classes in powershell

"Jim B" <jim.butts@gmail.com> wrote in message
news:1167805768.483223.168000@s34g2000cwa.googlegroups.com...
>I am trying to figure out why these lines work:
>
> PS C:\> $test = [system.net.webrequest]
> PS C:\> $test2 = [system.net.webclient]
>
> and this one generares an error:
>
> PS C:\> $testftp = [System.Net.WebRequestMethods.Ftp]
> Unable to find type [System.Net.WebRequestMethods.Ftp]: make sure that
> the assembly containing this type is loaded.
> At line:1 char:45
> + $testftp = [System.Net.WebRequestMethods.Ftp] <<<<


"WebRequestMethods.Ftp" is derived from the class container
"WebRequestMethods", so the right syntax in PowerShell is
"WebRequestMethods+Ftp".

Hope that helps,
Jacques

Old 01-04-2007   #4 (permalink)
Jim B
Guest


 

Re: invoking .net classes in powershell

This absolutely helps. Thank you. Is there someplace that the "+"
notation is documented? Was there some way for me to determine this on
my own?

On Jan 3, 11:27 am, "Jacques Barathon [MS]"
<jbara...@online.microsoft.com> wrote:
> "Jim B" <jim.bu...@gmail.com> wrote in messagenews:1167805768.483223.168000@s34g2000cwa.googlegroups.com...
>
> >I am trying to figure out why these lines work:

>
> > PS C:\> $test = [system.net.webrequest]
> > PS C:\> $test2 = [system.net.webclient]

>
> > and this one generares an error:

>
> > PS C:\> $testftp = [System.Net.WebRequestMethods.Ftp]
> > Unable to find type [System.Net.WebRequestMethods.Ftp]: make sure that
> > the assembly containing this type is loaded.
> > At line:1 char:45
> > + $testftp = [System.Net.WebRequestMethods.Ftp] <<<<"WebRequestMethods.Ftp" is derived from the class container

> "WebRequestMethods", so the right syntax in PowerShell is
> "WebRequestMethods+Ftp".
>
> Hope that helps,
> Jacques


Old 01-05-2007   #5 (permalink)
Jacques Barathon [MS]
Guest


 

Re: invoking .net classes in powershell

"Jim B" <jim.butts@gmail.com> wrote in message
news:1167952249.416317.180550@v33g2000cwv.googlegroups.com...
> This absolutely helps. Thank you. Is there someplace that the "+"
> notation is documented? Was there some way for me to determine this on
> my own?


I am not sure about the documentation. As for determining it on your own, I
figured it out thanks to the tab expansion feature (I use MOW's version
called PowerTab so you may want to install it before reading further:
http://thepowershellguy.com/blogs/po.../default.aspx).

Now that you have installed PowerTab, you can explore .NET types from your
console:

PS> [system.net.web # press Tab
PS> [System.Net.WebRequest] # press Tab again
PS> [System.Net.WebRequestMethods] # here you can see that there is a
closing bracket, which means that there is no known subtype

From there, if you know that there is a sub-class called "FTP", there is a
high chance that the parent class is a generic container class and that you
have to use the "+" notation.

That's a completely empirical approach, probably not 100% reliable but it
has worked for me the rare times I was confronted to this issue.

Jacques

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoking a certain section of a powershell file. greatbarrier86 PowerShell 20 11-08-2007 02:13 PM
Right-button on folder invoking PowerShell Hans Dingemans PowerShell 10 10-02-2007 03:39 PM
Invoking PowerShell functions with parameters from .NET: issues. Roman Kuzmin PowerShell 0 04-23-2007 07:35 AM
Invoking PowerShell from WScript via COM Joris van Lier PowerShell 1 03-28-2007 09:53 AM
Invoking Powershell from C# Janssen PowerShell 3 02-16-2007 06:42 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