1

Automating some IIS stuff with Powershell. I needed to add an net.msmq binding using the approach listed here: Why Powershell's New-WebBinding commandlet creates incorrect HostHeader?

Where I add using something like

New-ItemProperty -Path 'IIS:\Sites\Default Web Site' -Name Bindings -value @{protocol="net.msmq"; bindingInformation="server.domain.com"}

So now I need to automate removal of that binding (say the queue server changes). I have messed around with all the Collection cmdlets, and I cannot figure out a way to remove an item.

Get-ItemProperty -Path 'IIS\Sites\Default Web Site' -Name bindings 

will return a collection. I can iterate through with ForEach, but I cannot seem to find the magic command to remove an item once I find it.

Any thoughts?

Community
  • 1
  • 1
Taylor Bird
  • 7,767
  • 1
  • 25
  • 31

2 Answers2

1

This worked for me:

$prop = (get-ItemProperty -Path 'IIS:\Sites\Default Web Site' -Name bindings).Collection | ? {$_.Protocol -ne "net.msmq"}
Set-ItemProperty "IIS:\sites\Default Web Site" -name bindings -value $prop
Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
1

Remove-ItemProperty 'IIS:\Sites\DemoSite' -Name bindings -AtElement @{protocol="http";bindingInformation="*:80:DemoSite2"}

straight off the technet......