Solved

Explanation of Powershell Syntax

Posted on 2010-09-14
3
719 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
3 Comments
 
LVL 70

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now