# PowerShell比较运算符

## 本文概述

PowerShell支持以下比较运算符：

1. 平等经营者
2. 匹配运算符
3. 遏制运营商
4. 替代运营商
5. 类型运算符

## 平等经营者

1. -eq(等于)
2. -ne(不等于)
3. -gt(大于)
4. -ge(大于或等于)
5. -lt(小于)
6. -le(小于或等于)

-eq(等于)

``````\$a=10
\$b=10
(\$a -eq \$b)``````

-ne(等于)

``````\$a=10
\$b=10
(\$a -ne \$b)``````

-gt(大于)

``````\$a=20
\$b=10
(\$a -gt \$b)``````

-ge(大于或等于)

``````\$a=10
\$b=10
(\$a -ge \$b)``````

-lt(小于)

``````\$a=10
\$b=20
(\$a -lt \$b)``````

-le(小于或等于)

``````\$a=10
\$b=10
(\$a -le \$b)``````

## 匹配运算符

1. -喜欢
2. -比赛
3. -不匹配

-喜欢

``````\$a="PowerShell"
\$b="PowerShell"
\$a -like \$b``````

``````\$a="PowerShell"
\$b="*Shell"
\$a -like \$b``````

``````\$a="PowerShell"
\$b="windows"
\$a -notlike \$b``````

``````\$a="PowerShell"
\$b="*Shell"
\$a -notlike \$b``````

-比赛

``````\$a="January", "February", "March", "April"
\$b="Feb"
\$a -match \$b``````

-不匹配

``````\$a="PowerShell"
\$b="ell"
\$a -notmatch \$b``````

``````\$a="January", "February", "March", "April"
\$b="Feb"
\$a -notmatch \$b``````

``````January
March
April``````

## 遏制运营商

1. -包含
2. -不包含
3. -在
4. -notin

-包含

``````\$a="January", "February", "March", "April"
\$b="March"
\$a -contains \$b``````

-不包含

``````\$a="January", "February", "March", "April"
\$b="March"
\$a -notcontains \$b``````

-在

``````\$b="March"
\$b="February", "March", "April"
\$a -in \$b``````

-notin

``````\$b="March"
\$b="February", "March", "April"
\$a -notin \$b``````

## 替换运算符

``<input> <operator> <original> , <substitute>``

``````\$a="Windows and Linux Operating system"
\$a -replace "Linux" , "MacOS"``````

``Windows and MacOS operating system``

## 类型比较运算符

PowerShell支持以下两种类型比较运算符：

1. -是
2. -不是

-是

``````\$a=1
\$a -is [int]``````

-不是

``````\$a="1"
\$a -is [int]``````

• 回顶