PowerShell 用两种模式解析命令行 Command mode 和expression mode。当命令有如下特征时PowerShell采用Expression方式
· 命令以数字开头,例如2+2
· 以$ 开始, 例如$a
· 以双引号开始,例如”This is a string”.
· 以点.后跟数字开始,例如.5
当命令有如下特征时PowerShell采用Command方式
· 以字母开始, 例如write-host 3+2
· 以点后跟空格开始,例如 . “MyScript.ps1”
· 以点后跟字母开始,例如 .SomeCommand
· 以&开始,例如 &something
Get-process, 可用于察看当前本机运行的process。Get-Service 可查看本机上所有可用Service.
Where-Object 用于过滤显示结果
$_ 在pipeline中代表这上一个命令传到下一个命令的对象。
PowerShell允许输入动词和-后用Tab选择完整的命令(匹配的命令将按字母表顺序轮换)。例如输入get-se后按Tab键,屏幕上将会显示Get-Service
Where-object 用于按照包含在波浪括号{}中的条件过滤对象
Operator | Meaning | Meaning |
-lt | Less than | 小于 |
-le | Less than or equal to | 小于等于 |
-gt | Greater than | 大于 |
-ge | Greater than or equal to | 大于等于 |
-eq | equal to | 等于 |
-ne | Not equal to | 不等于 |
-contains | contains | 包含 |
-notcontains | Doesn’t contain | 不包含 |
-like | Matches using wildcards | 与通配符字串匹配 |
-notlike | Negated matching using wildcards | 与通配符字串不匹配 |
-match | Matches using regular expressions | 与正则表达式匹配 |
-notmatch | Negated matching using regular expressions | 与正则表达式不匹配 |
-band | Bitwise AND | 位与 |
-bor | Bitwise or | 位或 |
-is | is of a specified type | 是指定的类型 |
-isnot | is Not of a specified type | 不是指定的类型 |
缺省的字符串比较是大小写不敏感的,可用下列操作指定字符串比较方式 | ||
Case-sensitive less than | 大小写敏感小于 | |
-cle | Case-sensitive less than or equal to | 大小写敏感小于等于 |
-cgt | Case-sensitive greater than | 大小写敏感大于 |
-cge | Case-sensitive greater than or equal to | 大小写敏感大于等于 |
-ceq | Case-sensitive equals | 大小写敏感等于 |
-cne | Case-sensitive not equal | 大小写敏感不等于 |
-clike | eCase-sensitive matching using wildcards | 大小写敏感与通配符字串匹配 |
-cnotlike | Case-sensitive failure to match using wildcards | 大小写敏感与通配符字串不匹配 |
-ccontains | Case-sensitive contains | 大小写敏感包含 |
-cnotcontains | Case-sensitive doesn¡¯t contain | 大小写敏感不包含 |
-cmatch | Case-sensitive match using regular expressions | 大小写敏感与正则表达式匹配 |
-cnotmatch | Case-sensitive failure to match using regular expressions | 大小写敏感与正则表达式不匹配 |
Sort-object用于排序, 缺省时递增顺序,-descending, 递减。 比如 get-process|where-object {$_.processname -match“sql”} |sort-object –descending $_.processname
Group-object 用于分组