Solved

Explanation of Powershell Syntax

Posted on 2010-09-14
3
724 Views
Last Modified: 2012-05-10
Hi Everyone,

My question relates to a line of PowerShell code that I have come across in a script that automates FTP uploads.

The line in question is:
$request.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

Instead, I thought that it might have been as follows (but this doesn't work):
$request.Method = [System.Net.WebRequestMethods.Ftp]::UploadFile

Really, I would like someone to explain to me why using the '+' sign instead of '.' means the difference between the overall script working or not.

Thanks so much in advance.
0
Comment
Question by:AlanFrazer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33671797

You need this in a .NET developer area really. I suspect there's a better description than I'll come up with here.

The WebRequestMethods class is a container, it contains the FTP class. FTP itself is a sub-class, and to access the sub-class in PowerShell you must use the + notation.

To the first is correct and if you run it as-is you should get STOR back if you run it alone.

Your request is throwing an error?

Chris
0
 
LVL 17

Accepted Solution

by:
Learnctx earned 50 total points
ID: 33679431
It is because you're dealing with a nested class. .NET developers would give you a much better answer I'm sure.

But have a look at some of these articles (search for nested ".net nested class plus" on Google and you'll find lots of info on that).

http://blogs.msdn.com/b/powershell/archive/2009/08/27/plus-in-net-class-names.aspx
http://msdn.microsoft.com/en-us/library/aa332510%28VS.71%29.aspx
http://geekswithblogs.net/shahed/archive/2008/11/07/126838.aspx
0
 

Author Closing Comment

by:AlanFrazer
ID: 33714483
Thank you very much for your help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question