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
?
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With