Wie Sie add-Attribut, falls es nicht existiert mit PowerShell?

Im web.config-Datei habe ich zum aktivieren httpGetEnabled und httpsGetEnabled - Attribute, wenn Sie nicht existieren.

$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
    }

Ich bin in der Lage, auf set-und get-Attribut-Werte mit PowerShell, aber ich weiß nicht, wie hinzufügen ein neues Attribut mit PowerShell. Es isno ' Hilfe zur Verfügung, mit Get-help für Attribute hinzufügen. Wie fügen Sie ein neues Attribut mit PowerShell?

InformationsquelleAutor Samselvaprabu | 2015-05-12

Schreibe einen Kommentar