powershell - IIS条件网址重写匹配类型的Powershell脚本

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

最佳答案

MatchType是具有三个值的枚举:

IsDirectory = 2     
IsFile      = 1     
Pattern     = 0

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

# or this should also work:
matchType = 0

(Source: MS Docs)

要将其设置为“匹配模式”,请设置:
negate = 'False'

关于powershell - IIS条件网址重写匹配类型的Powershell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54324432/

相关文章:

.net - 无法保存 applicationHost.config 文件

iis - 无法使用 WAMP ,端口 80 由 IIS 7.5 使用

powershell - 使用PowerShell自动构建dwproj

powershell - [ordered] 的用例,新的 PowerShell 3.0 功能

Powershell 模块和管理员权限

asp.net - asp.net 在 iis 中访问该路径被拒绝

c# - 如何在没有登录弹出窗口的情况下自动验证 Windows 集成?

javascript - 从 Zendesk(javascript) 连接到 Acumatica(IIS)

arrays - 如何处理 “distorted” array-output

powershell - 如何在 Powershell 中迭代键/值输出?