茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1673215 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
HoneyMoon_Day3_00006.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2015/12/21 10:06:27
PowerShell Comparison Operators

The following operators are all Case-Insensitive by default:
 -eq             Equal
 -ne             Not equal
 -ge             Greater than or equal
 -gt             Greater than
 -lt             Less than
 -le             Less than or equal
 -like           Wildcard comparison
 -notlike        Wildcard comparison
 -match          Regular expression comparison
 -notmatch       Regular expression comparison
 -replace        Replace operator
 -contains       Containment operator
 -notcontains    Containment operator
 -shl            Shift bits left (PowerShell 3.0)
 -shr            Shift bits right – preserves sign for signed values.(PowerShell 3.0)
 -in             Like –contains, but with the operands reversed.(PowerShell 3.0)
 -notin          Like –notcontains, but with the operands reversed.(PowerShell 3.0)

To perform a Case-Sensitive comparison just prefix any of the above with "c"
for example -ceq for case-sensitive Equals or -creplace for case-sensitive replace.

Similarly prefixing with "i" will explicitly make the operator case insensitive.
Types
 -is     Is of a type
 -isnot  Is not of a type
 -as     As a type, no error if conversion fails

Logical operators
 -and    Logical And
 -or     Logical Or
 -not    logical not
  !      logical not

Bitwise operators
 -band   Bitwise and
 -bor    Bitwise or

Format Operator
 "format_string" -f Object1, Object2,...

The format_string is in the form: {0,-5} {1,-20} {2,-10}
In each set of braces, the first number, before the comma refers to the column.
The second number, after the comma determines the padding (how many characters)
If the second number is negative, it not only pads the element, but aligns it vertically. Optionally the second number can be used for formatting :hh :mm :C :p

Examples
$demo = $null
if (-Not ($demo)) { write "Zero, null or Empty"}
if (!($demo)) { write "Zero, null or Empty"}

$myVar -is "String"
$myVar -eq 123
$myVar -ceq $myVar2
"abcdef" -like "abc*"
"abcdef" -replace "dEf","xyz"
$myVar1 -is "String" -and $myVar2 -is "Int"
"{2:N}" -f 24.4567
(1 -eq 1) -and -not (2 -gt 2)

$mycmd = ps | select id,ProcessName
foreach ($proc in $mycmd) {"{0,-8}{1,-20}" -f $proc.id, $proc.ProcessName}


原文出處:Comparison operators | PowerShell | SS64.com
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|