"Explore PowerShell" "11" function

Source: Internet
Author: User

A script may have a lot of functionality, but not all of it is done through a piece of code. In an excellent script, the independence of each functional code can be guaranteed, ensuring that the script is highly available and maintainable, and that when we improve or subtract functionality, we simply delete the corresponding code block. Typically, a code block refers to a function, calling a function, or executing a different block of code in order to implement a variety of functions.

Let's look at one example:

function Time {Get-Date} <enter>

In this way, we have a new function "time" whose function implementation code is "{get-date}".

Try calling it:

As with programming languages, custom functions can also declare parameters:

function (keyword) functions name (parameter) {code}

For example:

function add ($x,$y)
{
     $n = $x + $y
     “$x+$y=$n”
}

Run Result:

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.