如下说明是翻译
PowerShell
中
: help Get-Command
产生的帮助信息
.
译者
: Edengundam(
马涛
)
Get-Command
大纲
取得
cmdlet
的基本信息和其他关于
Windows PowerShell
命令的元素
.
语法
Get-Command [[-argumentList] <Object[]>] [-verb <string[]>] [-noun <string[]>] [-totalCount <int>] [-syntax] [-pSSnapIn <string[]>] [<CommonParameters>]
Get-Command [[-name] <string[]>] [[-argumentList] <Object[]>] [-commandType {<Alias> | <Function> | <Filter> | <Cmdlet> | <ExternalScript> | <Application> | <Script> | <All>}] [-totalCount <int>] [-syntax] [<CommonParameters>]
详细描述
Get-Command cmdlet
取得
cmdlet
的基本信息和其他关于
Windows PowerShell
命令的元素
,
例如
:
文件
,
函数和
Windows PowerShell
提供程序
.
参数
-name <string[]>
只检索指定名称的
cmdlet
或命令元素的信息
. <String>
表示
cmdlet
或命令元素的完整或部分名称
.
允许使用通配符
.
强制参数
?
|
false
|
参数位置
?
|
1
|
默认值
|
|
允许从管道绑定输入
?
|
true (
根据值
,
根据属性名
)
|
允许通配符扩展
?
|
true
|
-verb <string[]>
取得
cmdlet
名称中包含指定动词的
cmdlet
信息
. <String>
表示一个或多个动词或动词模式
,
例如
: "remove"
或
*et".
允许使用通配符
.
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
Null
|
允许从管道绑定输入
?
|
true (
根据属性名
)
|
允许通配符扩展
?
|
true
|
-noun <string[]>
取得
cmdlet
名称中包含指定名词的
cmdlet
信息
. <String>
表示一个或多个名词或名词模式
,
例如
: "process"
或
"*item*".
允许使用通配符
.
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
Null
|
允许从管道绑定输入
?
|
true (
根据属性名
)
|
允许通配符扩展
?
|
true
|
-commandType <CommandTypes>
只检索指定类型的命令对象
. <CommandTypes>
的合法取值
:
·
Alias
·
ExternalScript
·
All Filter
·
Application
·
Function
·
Cmdlet (
默认值
)
·
Script
"Application"
表示系统上所有可以在
PowerShell
中运行的非
PowerShell
文件
,
包括
: Windows PowerShell
路径中的
.txt, .exe
和
.dll
文件
.
"Filter"
和
"Function"
表示所有
Windows PowerShell
函数
.
你可以使用
CommandType
或它别名
: Type. (
译注
:
参数别名
)
下面列出了此参数接受的取值
:
·
Alias
·
Function
·
Filter
·
Cmdlet
·
ExternalScript
·
Application
·
Script
·
All
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
Cmdlet
|
允许从管道绑定输入
?
|
true (
根据属性名
)
|
允许通配符扩展
?
|
false
|
-totalCount <int>
确定取得
Windows PowerShell
的命令元素数量
.
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
(all)
|
允许从管道绑定输入
?
|
true (
根据属性名
)
|
允许通配符扩展
?
|
false
|
-syntax <SwitchParameter>
只检索关于命令元素指定的数据
.
·
对于别名
,
取得标准名称
.
·
对于
cmdlet,
检索语法
.
·
对于函数和筛选器
,
检索函数的定义
.
·
对于脚本和应用程序
(
文件
),
检索路径和文件名
.
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
False
|
允许从管道绑定输入
?
|
true (
根据属性名
)
|
允许通配符扩展
?
|
false
|
-argumentList <Object[]>
取得关于
cmdlet
使用指定参数
("arguments",
例如
:
路径
)
时的信息
.
要检测动态添加给
cmdlet
的参数
,
将
<Object[]>
替换为
Windows PowerShell
提供程序或
cmdlet
的特定参数
,
例如
: "HKML/Software"
或
"cert:/my".
强制参数
?
|
false
|
参数位置
?
|
2
|
默认值
|
|
允许从管道绑定输入
?
|
false
|
允许通配符扩展
?
|
false
|
-PSSnapIn <string[]>
获取指定的
Windows PowerShell
管理单元
(snap-in)
支持的
cmdlet.
更多信息
,
键入
"get-help about-PSSnapins".
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
unspecified
|
允许从管道绑定输入
?
|
true (
根据属性名
)
|
允许通配符扩展
?
|
true
|
<
公共参数
>
此命令支持公共参数
: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable.
更多信息
,
输入
, "get-help about_commonparameters".
输入类型
String
返回类型
Object
注意
更多信息
,
输入
"Get-Help Get-Command -detailed".
需要技术信息
,
输入
"Get-Help Get-Command -full".
当不指定任何参数时
, "Get-Command"
取得
Windows PowerShell
的
cmdlet
信息
.
使用参数来限定取得元素
.
默认情况下
, Get-Command
按照发现元素的顺序返回
.
发现顺序也就是当命令项产生歧义时
,
执行的顺序
.
例如
,
如果项的发现顺序是
notepad.exe, notepad.cmd
和
notepad.ps1,
你执行
"Notepad,"
系统将会运行
Notepad.exe.
发现顺序经常提供非常有价值的信息
.
如果你需要数据以其他方式排序
,
使用
Sort-Object cmdlet
进行排序
.
如果需要为该命令提供多个参数
,
请使用逗号进行分隔
.
例如
, "<parameter-name> <value1>, <value2>".
你可以使用
Get-Command
的
内建别名
"gcm".
需要更多信息
,
查看
About_Alias
.
例
1
C:/PS>get-command
此命令取得
Windows PowerShell
所有的
cmdlet
的信息
.
默认输出列出命令类型
("Cmdlet"), cmdlet
名称和
syntax.
例
2
C:/PS>get-command -verb set | format-list
此命令检索动词为
set
的
cmdlet
信息
,
并且以列表方式显示信息
.
列表格式包括了一些在表格显示时忽略的域
,
包括完整的语法
.
要显示所有的域
(
对象所有的属性
),
键入
"get-command -verb set | format list *".
例
3
C:/PS>get-command | sort-object noun | format-table -group noun
此命令取得所有的
cmdlet,
并根据
cmdlet
名称中名词的字母顺序进行排序
,
最后根据名词分组显示
.
这种显示可以帮助你查找特定任务的
cmdlet.
默认情况下
, Get-Command
将会按照系统发现命令的顺序进行显示
,
发现顺序也是当执行的命令具有歧义时
,
执行的顺序
.
例
4
C:/PS>get-command -pssnapin Microsoft.PowerShell.Security
此命令取得
Microsoft.PowerShell.Security
管理单元中的
cmdlet
信息
.
例
5
C:/PS>get-command get-childitem -ArgumentList cert: | format-list
此命令用来检索关于
Get-Childitem
在和
Windows PowerShell
证书提供程序一起使用时
Get-Childitem cmdlet
的信息
.
当你对比输出中显示的语法和忽略
ArgumentList
参数时的语法时
,
你将会发现证书提供程序动态的为
Get-ChildItem cmdlet
添加了参数
CodeSigningCert.
例
6
C:/PS>(get-command get-childitem -ArgumentList cert:).parametersets[0].parameters | where-object { $_.IsDynamic }
此命令只返回当与
Windows PowerShell
证书提供程序一起使用时
,
动态添加给
Get-Childitem
cmdlet
的参数
.
这是前面例子中的替换方法
.
此命令中
, "get-command get-childitem -ArgumentList cert:"
首先被处理
.
它使用
Get-Command
请求关于
Get-Childitem cmdlet
与证书提供程序一起使用的信息
. ".parametersets[0]"
选择
"get-childitem -argumentList cert:"
的第一个参数集
(
集合
0),
接下来
".parameters"
参数集中的参数
.
被选择的参数通过管道发送给
Where-Object cmdlet,
后者测试每个参数
("$_.")
的
IsDynamic
属性
.
要在命令中查看对象的属性
,
使用
Get-Member
.
例
7
C:/PS>get-command *
此命令检索
Windows PowerShell
中所有可用的元素的信息
,
包括
:
文件
,
函数
,
别名和
cmdlet.
相关链接
Get-Help
Get-PSDrive
Get-Member