Powershell 删除IIS授权规则“;“所有用户”;
我正在尝试从我们的一个web服务中删除特定的IIS授权规则。 我需要以“允许”模式删除用户“所有用户” 我试着用这个命令Powershell 删除IIS授权规则“;“所有用户”;,powershell,iis,authorization,Powershell,Iis,Authorization,我正在尝试从我们的一个web服务中删除特定的IIS授权规则。 我需要以“允许”模式删除用户“所有用户” 我试着用这个命令 Clear-Webconfiguration -Filter /system.webServer/security/authorization -Force -PSPath 'IIS:\sites\IAI Application Customizer' 我可以删除所有创建的规则,但只有“所有用户”规则仍然存在 我希望你能帮我解决这个问题。 谢谢也许您可以更改该服务的web.
Clear-Webconfiguration -Filter /system.webServer/security/authorization -Force -PSPath 'IIS:\sites\IAI Application Customizer'
我可以删除所有创建的规则,但只有“所有用户”规则仍然存在
我希望你能帮我解决这个问题。
谢谢也许您可以更改该服务的
web.config
文件
<authorization>
<remove accessType="Allow" users="*" />
</authorization>
这是我的解决方案
$webconfig路径=“C:\Users\SOGL\u D\Desktop\test.xml”
$xml=[xml](获取内容$webconfig路径)#创建xml对象并打开web.config文件
foreach($xml.configuration.system.webServer.security.authorization.add中的项)#遍历所有模块
{
如果($item.users-eq“*”)#检查是否要删除当前模块
{
$xml.configuration.“system.webServer.security.authorization.RemoveChild($item);#找到所需的模块后将其删除
}
}
$xml.Save($webconfig路径)#保存更新后的web.config文件
这是一个已知的问题,我至少可以用IIS7重现:
您必须调用Clear WebConfiguration
两次才能删除所有继承的规则。例如:
Clear-WebConfiguration -Filter "/system.webServer/security/authorization/add[@users='*' and @roles='' and @verbs='']" -PSPath "IIS:\Sites\my_site"
Clear-WebConfiguration -Filter "/system.webServer/security/authorization/add[@users='*' and @roles='' and @verbs='']" -PSPath "IIS:\Sites\my_site"
Add-WebConfiguration -Filter "/system.webServer/security/authorization" -Value (@{AccessType="Allow"; Users="my_user"; Permissions="Read, Write"}) -PSPath "IIS:\Sites\my_site"
这对我很有用:
C:\Windows\System32\inetsrv\appcmd.exe设置配置
/部分:system.webServer/security/authorization
/-[accessType='Allow',users='*']
我使用了一个自动编程的pwoershell脚本。它在所有服务器上运行。所以没有人可以编辑它。