您得到的具体错误是由于-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 返回一个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 的输出。由于文档只是文本,您可以通过管道将其发送到 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