PowerShell Big Impression Series 3 FAQ, the truth? Add

Source: Internet
Author: User
Tags bind scalar

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.