[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Explanation of Powershell Syntax

Posted on 2010-09-14
3
Medium Priority
?
726 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 18

Accepted Solution

by:
Learnctx earned 150 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

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
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…

656 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