Introduction to some special operators commonly used in PowerShell _powershell

Source: Internet
Author: User
Tags foreach parent directory

An operator is invoked.

Syntax:& < executable path > [< parameter list
Example:

Copy Code code as follows:
$execPath = "D:\progra~1\flashfxp\flashfxp.exe"
$execArgs = "-upload ftp://u:p@ip:21"
$execArgs = $execArgs + "-remotepath= '"/"" "
$execArgs = $execArgs + "-localpath= '" d:\123\ ' ""
& $execPath $execArgs. Split ()

This is an example of a previous call to FlashFXP to upload a file, using the & call character.

Point (.), a multi-function operator.

1, call the external PS1 script file

Copy Code code as follows:
. D:\PowerShell\test.ps1

2. Member operators

Copy Code code as follows:
$ object. property; or $ object. Method ()

3. Path operator
one point (.) represents the current directory, two dots (... ) represents a parent directory.
such as:. \test.ps1, ... \POWERSHELL\TEST.PS1, these two expressions relative to the D:\POWERSHELL\TEST.PS1, are referring to themselves.

Two o'clock (.. ), the range operator.

This is exactly the same as the two points above that indicate the parent directory, but it is not the same place to use.
"1..5" means 1 to 5, and "5..1" means 5 to 1.
When we are programming, using foreach may be a similar usage:

Copy Code code as follows:
foreach ($i in 1..5) {
Write-host $i;
}

Double colon (::), static member operator.

When PowerShell programming, it is often used. NET, and its properties and methods. For example, the Thread.Sleep () method, to be invoked in PowerShell, is invoked in the following manner.

Copy Code code as follows:
[System.threading.thread]::sleep (10000);

(-f), the format operator.

Syntax: format string-F value 1, value 2,...
Example: "{0} {1:n} {2,-10}"-F 10000,[math]::p i, "good"

$ (), child expression operator.

Evaluates the value of an expression in parentheses, somewhat like the eval () function. Returns a scalar if the value is a result. If the value is multiple, an array is returned.
Example:

Copy Code code as follows:
$i = 200;
#返回值1000
$ ($i *5);
#返回一个逻辑磁盘的对象数组
$ (Get-wmiobject Win32_LogicalDisk)

@ (), array subexpression operator.

Returns the result of one or more statements through an array. If there is only one item, the array has only one member. Such as:

Copy Code code as follows:
@ (Get-wmiobject Win32_LogicalDisk)

The comma (,) array element operator.

When this operator is used as a two-dollar operator, commas are used to create an array that lists the elements of an array. Such as:

Copy Code code as follows:
$array = "A", "B", "C", "D"

When used as a unary operator, commas are used to create an array that contains only one member. Such as:
Copy Code code as follows:
$singleArray =, "a"

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.