![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | 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] <<<< |
| | #2 (permalink) |
| 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] <<<< > > |
| | #3 (permalink) |
| 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 |
| | #4 (permalink) |
| 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 |
| | #5 (permalink) |
| 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 |
| |
| |
![]() |
| 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 |