Get-Verb

获取批准的 PowerShell 谓词。

语法

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

说明

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

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

使用未经批准的谓词的命令仍在 PowerShell 中运行。 但是,在导入包含名称中包含未批准的谓词的命令的模块时,该 Import-Module 命令会显示一条警告消息。

注意

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

示例

示例 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 - 获取安全组中的所有已批准谓词

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[]
Position:0
Default value:All verbs
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Verb

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

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:True

输入

None

输出

VerbInfo

备注

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

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

  • 常见:定义几乎可以应用于任何 cmdlet 的泛型操作,例如 Add。
  • 通信:定义适用于通信的操作,例如“连接”。
  • 数据:定义适用于数据处理的操作,例如备份。
  • 诊断:定义应用于诊断的操作,例如调试。
  • 生命周期:定义应用于 cmdlet 生命周期的操作,例如 Complete。
  • 安全性:定义适用于安全性的操作,例如撤销。
  • 其他:定义其他类型的操作。

与 PowerShell 一起安装的一些 cmdlet(如 Tee-ObjectWhere-Object)使用未经批准的谓词。 这些 cmdlet 是历史例外,其谓词被归类为 保留