简体   繁体   English

如何快速删除 PowerShell 中的多个 IIS 绑定?

[英]How to remove multiple IIS bindings in PowerShell fast?

In a process of version upgrade, our current solution takes all bindings (except for two dummy urls) from one site and setting them on another site.在版本升级过程中,我们当前的解决方案从一个站点获取所有绑定(两个虚拟 url 除外)并将它们设置在另一个站点上。

I'm currently removing the bindings through PowerShell but it is super slow.我目前正在通过 PowerShell 删除绑定,但速度非常慢。 I've looked on about every thread in SO and almost every solution uses "Remove-WebBinding".我查看了 SO 中的每个线程,几乎每个解决方案都使用“Remove-WebBinding”。

This is my current code:这是我当前的代码:

Get-Website -Name $siteName | Get-WebBinding  | Where-Object { $_.HostHeader -notlike '*dummy*' } | Remove-WebBinding;

I have 272 (-2 dummy) bindings to remove and it takes more about 3 minutes.我有 272 个(-2 虚拟)绑定要删除,大约需要 3 分钟。

Any ideas how to do it faster?任何想法如何更快地做到这一点?

BTW: Adding all of those bindings one by one is super-slow too, but I guess if I'll find an answer here a similar solution would do for adding as well.顺便说一句:一个一个地添加所有这些绑定也非常慢,但我想如果我能在这里找到答案,类似的解决方案也可以添加。

Copied from the comment and expand it a little bit.从评论中复制并扩大一点。

Cause of Slowness缓慢的原因

WebAdministration cmdlets were designed a long while ago, which has many disadvantages. WebAdministration cmdlet 是很久以前设计的,它有很多缺点。

The slowness you observed can be explained as by design.您观察到的缓慢可以通过设计来解释。 Though it is not open sourced, we can guess that each call of Remove-WebBinding creates the relevant underlying objects (like ServerManager ) and then commits change to IIS configuration file.虽然它不是开源的,但我们可以猜测,每次调用Remove-WebBinding都会创建相关的底层对象(如ServerManager ),然后将更改提交到 IIS 配置文件。 Thus, the more bindings to remove, the longer it takes (and the more resources consumed).因此,要删除的绑定越多,花费的时间就越长(消耗的资源也就越多)。

Solution解决方案

For all in-support IIS releases today (8+), you should use IISAdministration cmdlets instead.对于今天 (8+) 的所有受支持的 IIS 版本,您应该改用IISAdministration cmdlet They are newly developed with both flexibility and performance in mind.它们是新开发的,兼顾了灵活性和性能。

By using a single ServerManager object and committing changes only once, removing bindings can be a lot faster.通过使用单个ServerManager object 并只提交一次更改,删除绑定可以快得多。

try to run below PowerShell script:尝试在 PowerShell 脚本下运行:

Import-Module WebAdministration  
Get-WebBinding -HostHeader 'dummy' | Remove-WebBinding -Confirm:$true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM