Linux资源管理之cgroups简介
2015-08-03 23:57
525 查看
Windows PowerShell Language Quick Reference
Native Support for Different Type Systems | ||||||||||||||||||||
Windows PowerShell adapts WMI, XML, ASDI, <city w:st="on"><place w:st="on">ADO</place></city>, and COM objects to provide a common syntax to access their properties and methods. Example $g = Get-WmiObject Win32_Process $g[0].Name # instead of $g[0].Properties[“Name”] | ||||||||||||||||||||
Arithmetic Binary Operators | ||||||||||||||||||||
| ||||||||||||||||||||
Array Operations | ||||||||||||||||||||
Does this array have a <metricconverter w:st="on" productid="3 in">3 in</metricconverter> it 1,2,3,5,3,2 –contains 3 Return all elements equal to 3: 1,2,3,5,3,2 –eq 3 Return all elements less than 3: 1,2,3,5,3,2 –lt 3 Test if 2 exists in collection: if (1, 3, 5 –contains 2) … Other operators: -gt, -le, -ge, -ne | ||||||||||||||||||||
Arrays | ||||||||||||||||||||
| ||||||||||||||||||||
Assignment Operators | ||||||||||||||||||||
=, +=, -=, *=, /=, %= | ||||||||||||||||||||
Associative Arrays (Hashtables) | ||||||||||||||||||||
| ||||||||||||||||||||
Boolean Values and Operators | ||||||||||||||||||||
| ||||||||||||||||||||
Break (Scripting) | ||||||||||||||||||||
The break commands exits a loop. It can take an optional LABEL to break to Example: while (1) { $a = something if ($a –eq 1) break; } | ||||||||||||||||||||
Command Expansion Operators | ||||||||||||||||||||
| ||||||||||||||||||||
Comments | ||||||||||||||||||||
# This is a comment because # is the first char of a token $a = “#This is not a comment…” $a = “something” # …but this is. Write-Host Hello#world | ||||||||||||||||||||
Comparison Operators | ||||||||||||||||||||
“i” or “c” may be prepended to get case-insensitive or case-sensitive operations (for example, –ceq ) | ||||||||||||||||||||
Continue (Scripting) | ||||||||||||||||||||
The continue statement continues the next iteration of a loop without breaking out of it. Example: while (1) { $a = something if ($a –eq 1) (continue) # This line is not reached unless $a == 1 } # This line is never reached. | ||||||||||||||||||||
Dot Sourcing | ||||||||||||||||||||
Dot sourcing allows running functions, script blocks, and scripts in the current scope rather than a local one. Example: . MyFunction If MyFunction sets a variable, it is set in the current scope rather than the function’s local scope. $a = {$x = Get-Process | Select –First 2} . $a #Evaluates the script block in the current scope | ||||||||||||||||||||
Escape Sequences | ||||||||||||||||||||
The Windows PowerShell escape character is the backwards apostrophe, or `. To make a character literal, precede it with `. To specify a ` use ``.
| ||||||||||||||||||||
Execution Order | ||||||||||||||||||||
Windows PowerShell attempts to resolve commands in the following order: aliases, functions, cmdlets, scripts, executables, and normal files. | ||||||||||||||||||||
For (Scripting) | ||||||||||||||||||||
[:label] for ([initializer]; [condition]; [iterator]) {} Example: for ($i = 0; $i –lt 5; $i++) {Write-Object $i} | ||||||||||||||||||||
Foreach (Scripting) | ||||||||||||||||||||
[:label] foreach (identifier in collection) {} Expression | foreach {} Expression | foreach {BEGIN{} PROCESS{} END{}} Examples: $i = 1,2,3 foreach ($z in $i) {Write-Object $z} Get-Process |foreach {BEGIN{$x=1} PROCESS{$X++} END{“$X Processes”}} | ||||||||||||||||||||
Functions (Scripting) | ||||||||||||||||||||
function MyFunction { write-object $args[0] } function test ([string]$label=”default label”,[int]$start=0) { BEGIN {$x=$start} PROCESS {“$label: $_”’; $x++} END{“$x total”} } | ||||||||||||||||||||
Filters (Scripting) | ||||||||||||||||||||
padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; width: 216pt; padding
相关文章推荐
|