This article is mainly to put some PowerShell often make people feel not accustomed to the place, and some internal treatment of the way to introduce. Learn a high-level language, often by its convenience, let you feel foggy, but I like the reason for PowerShell, because it is naked (at least looming), hehe, even if it does not disclose its source code, but the implementation of the logic through the Trace-command public out. Well, now is the beginning. I am more superficial, so I say the same thing, but I hope to have a great effect.
1. The role of Return
I was wondering if someone would say, "Ah?" Return is so simple to say? It's programmed to know. " But I can't help but say the difference in POWERSHELL's return, the general language, "Retrun" has the function of terminating functions and returning results. But in Powershell,return, it's just the former. But this is purely speculative, Because appearances make people feel that way. For instance:
function bar {write-host "123"
"567" return
"234"}
$result = Bar
What is the result in this time? The answer is an array with 567 and 234 in it. So it can be inferred that the "567" has the ability to return the result, and returns "234"? is more like the role of 234;retrun. So how do we usually get out of the running process information? We're going to use Write-host. Uh, uh.
2. The truth of the parameterbinding
Run this statement trace-command-name parameterbinding-pshost-expression {get-process-name *sql*}
Results:
Bind NAMED cmd line args [get-process]
bind arg [*sql*] to parameter [Name]
coerce arg type [System.String] to [Sy Stem. String[]]
ENCODING arg into collection
Binding collection parameter name:argument type [String],
parameter Type [system.string[]], collection type array, element type [System.String],
coerceelementtype
creating Array with element type [System.String] and 1 elements
Argument type String isn't IList, treating this as scalar
coerce ARG type [System.String] to [System.String]
Parameter and arg types the same.
Adding scalar element of type String to array position 0
executing VALIDATION metadata:
[System.Management.Auto Mation. Validatenotnulloremptyattribute]
bind arg [system.string[]] to Param [Name] successful
bind positional cmd Line args [get-process]
mandatory PARAMETER CHECK on cmdlet [get-process]
calling
beginprocessing Calling Processrecord
calling EndProcessing