【问题标题】:Power shell scripting for IIS Conditional Url Rewrite matchTypeIIS 条件 URL 重写匹配类型的 Powershell 脚本
【发布时间】:2019-01-23 09:54:12
【问题描述】:

我一直致力于在 IIS 上编写一个添加 Url 重写条件的 powershell 脚本。这是一个示例代码。

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 设置为“匹配模式”。这是我想要的 IIS 条件设置的相关匹配类型。设置这个需要的 matchType 是什么?

【问题讨论】:

    标签: powershell iis


    【解决方案1】:

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

    IsDirectory = 2     
    IsFile      = 1     
    Pattern     = 0
    

    “模式”是你想要的(你可以看到这实际上是默认值)。所以你可以使用:

    matchType = 'Pattern'
    
    # or this should also work:
    matchType = 0
    

    (Source: MS Docs)

    要将其设置为“匹配模式”,请设置:

    negate = 'False'
    

    【讨论】:

    • 当我不提供匹配类型时,它会自动将类型设置为“不匹配模式”类型。当 matchType = "Pattern" 时也会发生同样的事情。我要设置的是“匹配模​​式”类型。
    • @IshanthaKamal 我猜这是“否定”选项,但我不确定,目前无法测试。尝试将其设置为“False”
    • 这是“否定”选项设置。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    相关资源
    最近更新 更多