IIS条件网址重写matchType的Power Shell脚本

时间:2019-01-23 09:54:13

标签: powershell iis

我一直在努力在IIS上编写Powershell脚本,以添加Url重写条件。这是示例代码。

Add-WebConfigurationProperty -pspath 'iis:\sites\Sample'  -filter "system.webServer/rewrite/rules" -name "." -value @{name='Redirect www.google.com' ;patternSyntax='Regular Expressions' ;enabled='True' ;}
Set-WebConfigurationProperty -pspath $site -filter "$filterRoot/match" -name "url" -value "(^test/(.*)|^test($|/$))*"

$list = @{
    pspath = 'MACHINE/WEBROOT/APPHOST/Sample'
    filter = "/system.webServer/rewrite/rules/rule[@name='Redirect www.google.com']/conditions"
    Value = @{
        input = '{REMOTE_ADDR}'
        matchType ='0'
        pattern ='192.100.100.01'
        ignoreCase ='True'
        negate ='True'
    },
    @{
        input = '{REMOTE_ADDR}'
        matchType ='IsFile'
        pattern ='192.100.100.01'
        ignoreCase ='True'
        negate ='True'
    }
   }
   Add-WebConfiguration @list

在$ list中,我要将matchType设置为“ Matches the Pattern”。这就是我想要的IIS中条件设置的相关匹配类型。设置此项的matchType是什么?

1 个答案:

答案 0 :(得分:1)

MatchType是一个具有三个值的枚举:

IsDirectory = 2     
IsFile      = 1     
Pattern     = 0

“样式”是您想要的(您可以看到实际上是默认样式)。因此,您可以使用:

matchType = 'Pattern'

# or this should also work:
matchType = 0

Source: MS Docs

要将其设置为“匹配图案”,请设置:

negate = 'False'