gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:52:58 24 4
gpt4 key购买 nike

我一直在努力在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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com