首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得更多关于powershell cmdlet的信息?

如何获得更多关于powershell cmdlet的信息?
EN

Stack Overflow用户
提问于 2015-10-29 14:34:43
回答 1查看 415关注 0票数 0

我已经搜索了几个小时关于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吗?还是我使用了错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-29 14:46:41

您得到的具体错误是由于-Metadata参数是一个开关这一事实-它不接受任何参数。

指定-Metadata开关时,返回的对象包含一个Metadata属性。

要获得overrideMode的值,请执行以下操作:

代码语言:javascript
复制
(Get-WebConfiguration -Filter "/node/filter" -Metadata).Metadata.overrideMode

发现命令详细信息:

(我以Test-Path为例,但这适用于任何cmdlet)

您始终可以从获取有关cmdlet 语法的最基本信息。

代码语言:javascript
复制
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参数:

代码语言:javascript
复制
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):

代码语言:javascript
复制
# 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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33417138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档