Get-Verb

获取已批准的 PowerShell 谓词。

语法

Get-Verb
   [[-Verb] <String[]>]
   [[-Group] <String[]>]
   [<CommonParameters>]

说明

Get-Verb 函数获取被批准在 PowerShell 命令中使用的谓词。

建议 PowerShell cmdlet 名称和函数名称采用 Verb-Noun 格式,并且包含已批准的谓词。 这种做法使命令名称更加一致、可预测且更易于使用。

使用未经批准的谓词的命令仍可在 PowerShell 中运行。 但是,当导入某个模块(包含其名称中具有未经批准的谓词的命令)时,Import-Module 命令将显示一条警告消息。

注意

Get-Verb 返回的谓词列表可能不完整。 有关包含说明的已批准 PowerShell 谓词的更新列表,请参阅已批准的谓词

示例

示例 1 - 获取所有谓词的列表

Get-Verb

示例 2 - 获取以“un”开头的已批准谓词的列表

Get-Verb un*

Verb       AliasPrefix Group     Description
----       ----------- -----     -----------
Undo       un          Common    Sets a resource to its previous state
Unlock     uk          Common    Releases a resource that was locked
Unpublish  ub          Data      Makes a resource unavailable to others
Uninstall  us          Lifecycle Removes a resource from an indicated location
Unregister ur          Lifecycle Removes the entry for a resource from a repository
Unblock    ul          Security  Removes restrictions to a resource
Unprotect  up          Security  Removes safeguards from a resource that were added to prevent it from attack or loss

示例 3 - 获取 Security 组中所有已批准的谓词

Get-Verb -Group Security

Verb      AliasPrefix Group    Description
----      ----------- -----    -----------
Block     bl          Security Restricts access to a resource
Grant     gr          Security Allows access to a resource
Protect   pt          Security Safeguards a resource from attack or loss
Revoke    rk          Security Specifies an action that does not allow access to a resource
Unblock   ul          Security Removes restrictions to a resource
Unprotect up          Security Removes safeguards from a resource that were added to prevent it from attack or loss

示例 4 - 查找模块中具有未经批准的谓词的所有命令

Get-Command -Module Microsoft.PowerShell.Utility | Where-Object Verb -NotIn (Get-Verb).Verb

CommandType     Name            Version    Source
-----------     ----            -------    ------
Cmdlet          Sort-Object     3.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Tee-Object      3.1.0.0    Microsoft.PowerShell.Utility

参数

-Group

仅获取指定组。 输入组的名称。 不允许使用通配符。

此参数是在 PowerShell 6.0 中引入的。

Type:String[]
Accepted values:Common, Communications, Data, Diagnostic, Lifecycle, Other, Security
Position:1
Default value:All groups
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Verb

仅获取指定的谓词。 输入谓词的名称或名称模式。 允许使用通配符。

Type:String[]
Position:0
Default value:All verbs
Required:False
Accept pipeline input:True
Accept wildcard characters:True

输入

None

不能通过管道将对象传递给此 cmdlet。

输出

VerbInfo

备注

根据 PowerShell 谓词最常见的用途,将它们分配给组。 谓词组旨在简化谓词的查找和比较,而不会限制谓词的使用。 对于任意类型的命令,均可使用任何批准的谓词。

将每个 PowerShell 谓词分配给以下组之一。

  • Common:定义可应用于几乎所有的 cmdlet 的通用操作,例如 Add。
  • Communications:定义可应用于通信的操作,例如 Connect。
  • Data:定义可应用于数据处理的操作,例如 Backup。
  • Diagnostic:定义可应用于诊断的操作,例如 Debug。
  • Lifecycle:定义可应用于 cmdlet 的生命周期的操作,例如 Complete。
  • Security:定义可应用于安全的操作,例如 Revoke。
  • Other:定义其他类型的操作。

一些随 PowerShell 一起安装的 cmdlet(例如 Tee-ObjectWhere-Object)使用未经批准的谓词。 这些 cmdlet 是历史例外,且它们的谓词被归类为 reserved