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