Solved

Explanation of Powershell Syntax

Posted on 2010-09-14
3
722 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

730 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