我已经搜索了几个小时关于Get-WebConfiguration cmdlet在Web-Administration中,但没有任何效果。它的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吗?还是我使用了错误?
发布于 2015-10-29 14:46:41
您得到的具体错误是由于-Metadata参数是一个开关这一事实-它不接受任何参数。
指定-Metadata开关时,返回的对象包含一个Metadata属性。
要获得overrideMode的值,请执行以下操作:
(Get-WebConfiguration -Filter "/node/filter" -Metadata).Metadata.overrideMode发现命令详细信息:
(我以Test-Path为例,但这适用于任何cmdlet)
您始终可以从获取有关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的documentation,始终可以使用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 Pathhttps://stackoverflow.com/questions/33417138
复制相似问题