0

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.

I'm currently removing the bindings through PowerShell but it is super slow. I've looked on about every thread in SO and almost every solution uses "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.

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.

Idan Levi
  • 388
  • 3
  • 18
  • This doesn't look right `Where-Object { $_.HostHeader -notlike '*dummy*' | Remove-WebBinding }` - is it a typo? – Mathias R. Jessen May 20 '20 at 16:02
  • @MathiasR.Jessen -Yeah sorry I'll fix it in edit – Idan Levi May 20 '20 at 16:12
  • It is doomed to be slow when using WebAdministration cmdlets, as each call creates the relevant underlying objects over and over again. Switch to IISAadministration cmdlets and use a single `ServerManager` object. That's a lot faster. https://blogs.iis.net/bariscaglar/iisadministration-powershell-cmdlets-new-feature-in-windows-10-server-2016 – Lex Li May 20 '20 at 19:08
  • @LexLi That's the solution, thanks! My sctipt runs for 4 seconds now instead of 4 minutes (and it's a development environment which is a fracture of the size of the prod environment). Would you write a full answer that I can accept? – Idan Levi May 25 '20 at 09:51

2 Answers2

1

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.

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. 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. 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.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Thanks! that solved it. My sctipt runs for 4 seconds now instead of 4 minutes (and it's a development environment which is a fracture of the size of the prod environment). – Idan Levi May 25 '20 at 17:31
0

try to run below PowerShell script:

Import-Module WebAdministration  
Get-WebBinding -HostHeader 'dummy' | Remove-WebBinding -Confirm:$true
Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26