![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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] <<<< |
My System Specs![]() |
| | #2 (permalink) |
| | 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] <<<< > > |
My System Specs![]() |
| | #3 (permalink) |
| | 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 |
My System Specs![]() |
| | #4 (permalink) |
| | 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 |
My System Specs![]() |
| | #5 (permalink) |
| | 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 |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Invoking a certain section of a powershell file. | PowerShell | |||
| Right-button on folder invoking PowerShell | PowerShell | |||
| Invoking PowerShell functions with parameters from .NET: issues. | PowerShell | |||
| Invoking PowerShell from WScript via COM | PowerShell | |||
| Invoking Powershell from C# | PowerShell | |||