Powershell-operators

提供:Dev Guides
移動先:案内検索

Powershell-オペレーター

PowerShellは、変数を操作するための豊富な演算子セットを提供します。 私たちはすべてのPowerShell演算子を次のグループに分けることができます-

  • 算術演算子
  • 割り当て演算子
  • 比較演算子
  • 論理演算子
  • リダイレクト演算子
  • こぼれた演算子と結合演算子
  • タイプ演算子
  • 単項演算子

算術演算子

算術演算子は、代数で使用されるのと同じ方法で数式で使用されます。 次の表は、算術演算子を示しています-

整数変数Aが10を保持し、変数Bが20を保持すると仮定します-

リンク:/powershell/powershell_arithmatic_operators_examples [例を表示]

Operator Description Example
PLUS (Addition) Adds values on either side of the operator. A PLUS B will give 30
- (Subtraction) Subtracts right-hand operand from left-hand operand. A - B will give -10
AST (Multiplication) Multiplies values on either side of the operator. A AST B will give 200
/(Division) Divides left-hand operand by right-hand operand. B/A will give 2
% (Modulus) Divides left-hand operand by right-hand operand and returns remainder. B % A will give 0

比較演算子

PowerShell言語でサポートされている代入演算子は次のとおりです-

整数変数Aが10を保持し、変数Bが20を保持すると仮定します-

リンク:/powershell/powershell_comparison_operators_examples [例を表示]

オペレーター

説明

eq(等しい)

2つの値が等しいかどうかを比較します。

A -eq Bはfalseを返します

ne(等しくない)

2つの値が等しくないことを比較します。

A -ne Bはtrueを返します

gt(より大きい)

最初の値が2番目の値より大きいかどうかを比較します。

B -gt Aはtrueを返します

ge(以上)

最初の値を2番目の値以上に比較します。

B -ge Aは真を与える

lt(未満)

最初の値が2番目の値より小さいかどうかを比較します。

B -lt Aはfalseを返します

le(以下)

最初の値が2番目の値以下になるように比較します。

B -le Aは偽を与える

割り当て演算子

PowerShell言語でサポートされている代入演算子は次のとおりです-

リンク:/powershell/powershell_assignment_operators_examples [例を表示]

Operator Description Example
= Simple assignment operator. Assigns values from right side operands to left side operand. C = A PLUS B will assign value of A PLUS B into C
PLUS= Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand. C PLUS= A is equivalent to C = C PLUS A
-= Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand. C -= A is equivalent to C = C - A

論理演算子

次の表は、論理演算子を示しています-

ブール変数Aがtrueを保持し、変数Bがfalseを保持すると仮定します-

リンク:/powershell/powershell_logical_operators_examples [例を表示]

Operator Description Example
AND (logical and) Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A -AND B) is false
OR (logical or) Called Logical OR Operator. If any of the two operands are non-zero, then the condition becomes true. (A -OR B) is true
NOT (logical not) Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. -NOT(A -AND B) is true

その他の演算子

以下は、PowerShell言語でサポートされるさまざまな重要な演算子です-

リンク:/powershell/powershell_miscellaneous_operators_examples [例を表示]

オペレーター

説明

>(リダイレクトオペレーター)

リダイレクト演算子。 リダイレクトされたファイル/出力デバイスに印刷する出力を割り当てます。

dir> test.logは、test.logファイルのディレクトリリストを出力します