在IIS Powershell中添加GET HEAD和POST谓词

时间:2016-01-05 17:40:48

标签: powershell iis

我正在尝试使用以下命令将三个HTTP请求过滤器添加到我的applicationhost.config文件中:

Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="GET";allowed="True"} -Name collection
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="HEAD";allowed="True"} -Name collection
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="POST";allowed="True"} -Name collection

但是,每个后续行都会覆盖前一行,我只能添加一行。我想像这样添加所有三个:

        <verbs allowUnlisted="false">
            <add verb="GET" allowed="true" />
            <add verb="HEAD" allowed="true" />
            <add verb="POST" allowed="true" />
        </verbs>

我最终得到的是第一个GET被写入,然后HEAD覆盖GET,然后POST覆盖GET ...我只是希望所有三个都列出来。

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

使用Set-WebConfigurationProperty cmdlet时,实际上会覆盖相关配置部分元素的当前值。

如果您想值附加到多值属性,则应使用Add-WebConfigurationProperty代替:

Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="GET";allowed="True"} -Name Verbs -AtIndex 0
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="HEAD";allowed="True"} -Name Verbs -AtIndex 1
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="POST";allowed="True"} -Name Verbs -AtIndex 2

如果您想确保这三个谓词存在于集合中,请在添加之前使用Clear-WebConfiguration

Clear-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs'