In the web.config file I have to enable httpGetEnabled and httpsGetEnabled attributes if they don`t exist.
$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
}
I am able to set and get attribute values using PowerShell but I don't know how to add a new attribute using PowerShell. There isno help available using Get-help for adding attributes. How to add a new attribute using PowerShell?