如何获取有关 powershell cmdlet 的更多信息?
How to get more information about powershell cmdlets?
关于 Web-Administration
中的 Get-WebConfiguration
cmdlet,我已经谷歌搜索了几个小时,但无济于事。它的 MSDN 源没有解释 什么 -Metadata 参数接受作为输入。我在部署脚本中 运行 这个命令:
Set-WebConfiguration -PSPath IIS:\ -Filter /system.webServer/security/authentication/windowsAuthentication -Metadata overrideMode -value Allow
我正在开发一个库来读取这些值并在用户的环境不符合规范时提醒用户,所以我正在尝试使用:
Get-WebConfiguration -PSPath IIS:\ -Filter /system.webServer/security/authentication/windowsAuthentication -Metadata overrideMode
但我收到错误消息:A positional parameter cannot be found that accepts
argument 'overrideMode'.
我真的只是使用这个确切的语法设置这个确切的参数!
如何在 powershell 中找到有关参数的更多信息?是否有用于此的 cmdlet,还是我只是使用了错误的 Get-WebConfiguration?
您遇到的特定错误是由于 -Metadata
参数是一个开关 - 它不接受任何参数。
当您指定 -Metadata
开关时,返回的对象包含 Metadata
属性.
要获取 overrideMode
的值,请执行以下操作:
(Get-WebConfiguration -Filter "/node/filter" -Metadata).Metadata.overrideMode
发现命令详细信息:
(我以 Test-Path
为例,但这适用于任何 cmdlet)
您始终可以从 Get-Command -Syntax
:
获取有关 cmdlet 语法 的最基本信息
PS C:\> Get-Command Test-Path -Syntax
Test-Path [-Path] <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType <TestPathType>]
[-IsValid] [-Credential <pscredential>] [-UseTransaction] [-OlderThan <datetime>] [-NewerThan <datetime>]
[<CommonParameters>]
Test-Path -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType
<TestPathType>] [-IsValid] [-Credential <pscredential>] [-UseTransaction] [-OlderThan <datetime>] [-NewerThan
<datetime>] [<CommonParameters>]
Get-Command
returns 一个 CommandInfo
对象,您可以使用它来深入检查参数。
举个例子,我们来看看Get-WebConfiguration -Metadata
参数:
PS C:\> (Get-Command Get-WebConfiguration).Parameters["Metadata"]
Name : Metadata
ParameterType : System.Management.Automation.SwitchParameter
ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
IsDynamic : False
Aliases : {}
Attributes : {__AllParameterSets}
SwitchParameter : True
这里我们可以看到-Metadata
实际上是一个开关(注意SwitchParameter : True
属性)
要检索有关 cmdlet 的文档,您始终可以使用 Get-Help
cmdlet 获取有关特定 cmdlet 的 perldoc/manpage-like 输出。由于文档只是文本,您可以将其通过管道传输到 more
以逐步浏览它(同样,很像联机帮助页或 perldoc):
# Get a basic summary
Get-Help Test-Path
# Get more comprehensive summary
Get-Help Test-Path -Detailed
# Get the full documentation including examples
Get-Help Test-Path -Full
# Get just the examples
Get-Help Test-Path -Examples
# Get the help section about a specific parameter
Get-Help Test-Path -Parameter Path
关于 Web-Administration
中的 Get-WebConfiguration
cmdlet,我已经谷歌搜索了几个小时,但无济于事。它的 MSDN 源没有解释 什么 -Metadata 参数接受作为输入。我在部署脚本中 运行 这个命令:
Set-WebConfiguration -PSPath IIS:\ -Filter /system.webServer/security/authentication/windowsAuthentication -Metadata overrideMode -value Allow
我正在开发一个库来读取这些值并在用户的环境不符合规范时提醒用户,所以我正在尝试使用:
Get-WebConfiguration -PSPath IIS:\ -Filter /system.webServer/security/authentication/windowsAuthentication -Metadata overrideMode
但我收到错误消息:A positional parameter cannot be found that accepts
argument 'overrideMode'.
我真的只是使用这个确切的语法设置这个确切的参数!
如何在 powershell 中找到有关参数的更多信息?是否有用于此的 cmdlet,还是我只是使用了错误的 Get-WebConfiguration?
您遇到的特定错误是由于 -Metadata
参数是一个开关 - 它不接受任何参数。
当您指定 -Metadata
开关时,返回的对象包含 Metadata
属性.
要获取 overrideMode
的值,请执行以下操作:
(Get-WebConfiguration -Filter "/node/filter" -Metadata).Metadata.overrideMode
发现命令详细信息:
(我以 Test-Path
为例,但这适用于任何 cmdlet)
您始终可以从 Get-Command -Syntax
:
PS C:\> Get-Command Test-Path -Syntax
Test-Path [-Path] <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType <TestPathType>]
[-IsValid] [-Credential <pscredential>] [-UseTransaction] [-OlderThan <datetime>] [-NewerThan <datetime>]
[<CommonParameters>]
Test-Path -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PathType
<TestPathType>] [-IsValid] [-Credential <pscredential>] [-UseTransaction] [-OlderThan <datetime>] [-NewerThan
<datetime>] [<CommonParameters>]
Get-Command
returns 一个 CommandInfo
对象,您可以使用它来深入检查参数。
举个例子,我们来看看Get-WebConfiguration -Metadata
参数:
PS C:\> (Get-Command Get-WebConfiguration).Parameters["Metadata"]
Name : Metadata
ParameterType : System.Management.Automation.SwitchParameter
ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
IsDynamic : False
Aliases : {}
Attributes : {__AllParameterSets}
SwitchParameter : True
这里我们可以看到-Metadata
实际上是一个开关(注意SwitchParameter : True
属性)
要检索有关 cmdlet 的文档,您始终可以使用 Get-Help
cmdlet 获取有关特定 cmdlet 的 perldoc/manpage-like 输出。由于文档只是文本,您可以将其通过管道传输到 more
以逐步浏览它(同样,很像联机帮助页或 perldoc):
# Get a basic summary
Get-Help Test-Path
# Get more comprehensive summary
Get-Help Test-Path -Detailed
# Get the full documentation including examples
Get-Help Test-Path -Full
# Get just the examples
Get-Help Test-Path -Examples
# Get the help section about a specific parameter
Get-Help Test-Path -Parameter Path