【发布时间】:2015-07-23 06:36:33
【问题描述】:
在 web.config 文件中,如果 httpGetEnabled 和 httpsGetEnabled 属性不存在,我必须启用它们。
$Path = "c:\web.config"
$XPath = "/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior"
if ( Select-XML -Path $Path -Xpath $XPath ) {
"Path available"
$attributePath = $Xpath +="/serviceMetadata"
"Attribute path is $attributePath"
If (Get-XMLAttribute -Path $Path -Xpath $attributePath -attribute "httpGetEnabled" ) {
"httpGetEnabled is present"
}
ElseIf (Get-XMLAttribute -Path $Path -Xpath $attributePath -attribute "httpsGetEnabled") {
"httpsGetEnabled is present"
}
Else {
"Add both httpGetEnabled and httpsGetEnabled attribute with the value true and false accordingly"
$attributeset = @" httpGetEnabled="false" "@
New-Attribute -path $path -xpath $XPath -attributeset $attributeset
}
我能够使用 PowerShell 设置和获取属性值,但我不知道如何使用 PowerShell添加新属性。使用Get-help 添加属性没有帮助。如何使用 PowerShell 添加新属性?
【问题讨论】:
标签: xml powershell xpath powershell-2.0