Solved

Explanation of Powershell Syntax

Posted on 2010-09-14
3
717 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 16

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
A procedure for exporting installed hotfix details of remote computers using powershell
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…
This video discusses moving either the default database or any database to a new volume.

708 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

21 Experts available now in Live!

Get 1:1 Help Now