Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special use of plus (+) sign in Powershell

Tags:

powershell

Aside from its natural use, i.e. addition of two arguments, you can also use a plus + sign in Powershell to do special calls like this one:

[System.Net.WebRequestMethods+Ftp]::UploadFile

UploadFile is a public static field, according to MSDN, hence the double colon :: - everything is clear so far. But why is Ftp class so special, that instead of a dot ., it needs a +? I could not find any documentation on this part (official or not).

Are there any other uses for + except WebRequestMethods+Ftp?

like image 993
Neolisk Avatar asked Jan 03 '13 15:01

Neolisk


People also ask

What does the += mean in PowerShell?

Windows PowerShell. When the value of the variable is an array, the += operator appends the values on the right side of the operator to the array. Unless the array is explicitly typed by casting, you can append any type of value to the array, as follows: PowerShell Copy.

What does $() mean in PowerShell?

The $() is the subexpression operator. It causes the contained expressions to be evaluated and it returns all expressions as an array (if there is more than one) or as a scalar (single value).

What does @{ mean in PowerShell?

In PowerShell V2, @ is also the Splat operator. PS> # First use it to create a hashtable of parameters: PS> $params = @{path = "c:\temp"; Recurse= $true} PS> # Then use it to SPLAT the parameters - which is to say to expand a hash table PS> # into a set of command line parameters.


1 Answers

The WebRequestMethods class is a container, it contains the FTP class. FTP itself is a nested-class, and to access the nested-class in PowerShell (or C#, for that matter) you must use the + notation. More information here.

like image 152
David Brabant Avatar answered Oct 22 '22 02:10

David Brabant