PowerShell variable--powershell three min (vii)

Source: Internet
Author: User

with the previous PowerShell foundation, today we are going to learn a usage that can greatly improve the efficiency of PowerShell--variables


Jan said, the variable is a box with a name in memory ~~~~~ you can put everything you want to store in this " box ". Then visit the box by name.

During the access process, you can store, add, or retrieve things from the inside.

These things always reside in the box. and allows you to use them over and over again.


The procedure for defining a variable is as follows: The variable starts with the $ symbol, and then any name you want is entered.

very simple, when you want to use only need to re-enter the $var can be used

Of course, the variable can not only enter simple characters, but also can directly assign the result of the command to the variable

and even piping.

By calling variables, we can put frequently used information into variables to facilitate the use of subsequent commands, without having to enter each time.


When re-use, there are a few points to note:

    • Variable names usually contain letters, numbers, and underscores

    • You can include spaces, but you must enclose them in curly braces, and it is not recommended to name them.

    • When you close PowerShell, all the variables you create will be emptied


In addition to the custom variables, there are some variables built into PowerShell, you can view through get-variable, when defining variable names, be careful not to conflict with the built-in variable names


Now that you're done with the definition, here's a quick introduction to the variable type, usually with a character string that satisfies most of the requirements, but sometimes you need to limit the number, or the date, so long you need to force the declaration of the variable type.

Mandatory declarations only need to be preceded by parentheses [] when defining variables, and then by writing variable types

Like what

If the input data does not match the declared variable type, an error is generated and the value cannot be assigned

The following common data types are described here, such as


All right, today's three minutes to this, you hands up ~ ~


PowerShell variable--powershell three min (vii)

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.