PowerShell syntax and powershell syntax

Source: Internet
Author: User

PowerShell syntax and powershell syntax
Note

• # Statements

• <# Statement #>

Variable

• Naming rules $ as the prefix

• Use letters, numbers, and underscores

• View all variables Get-ChildItem variable: or Get-Varialbe

• Get the Scope Variable Get-Variable-Scope [Local | Global]

• Instantiate an Object $ dt = New-Object DateTime

Array

• Define $ arr = 1, 2, 4

• $ Arr = 1 .. 4

• Values: $ arr [1, 3], $ arr [1, 3 + 2], and $ arr [1 .. 3 + 2]

• Assign $ a, $ B = 1, 2, $ B, $ a = $ a, $ B

• Array merging using operators and operators

• Comparison operators can filter array content

Hashtable

• Integration of Hashtable in PowerShell

• Definition method @ {a = 1; B = "t "}

• Merge operator @ {a = 1} + @ {B = 2}

• If the value is $ ht = @ {a = 1}, use $ ht ["a"] $ ht..

• Other operation methods are consistent with CRL objects

String/other objects

• Multi-line string @"...."@

• Character escape characters such as "'n"

• Copy string "a" * 2

• Convert a string into an XML object [xml] "<a> 12 </a>"

Process Control

• If () {} elseif {} else {}

• Switch () {value1 {...; Break} value2 {....; Break }}

• Foreach ($ xxx in $ yyy ){}

• For ($ I = 0; $ I-le 100; $ I ++ ){}

• While (){}

• Do {} while ()

• Do {} ()

Method

Function methodName {

Param ($ size) # Parameter

# Executed statements

}

Or

Function methodName ($ p ){

# Executed statements

}

CLR/DLR object

• Static member access [DateTime]: Now

• Instantiate $ dt = new-object DateTime (, 9 );

• Instance Member access $ dt. AddDays (100)

• Use of Generic types $ l = new-object System. Collections. Generic. List [int]

• Get all members of an object Get-Member-InputObject $ l

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.