Taylor Bird
Taylor Bird

Reputation: 8017

Remove a net.msmq binding from IIS using Powershell

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?

Upvotes: 1

Views: 1299

Answers (2)

ScriptMechanic
ScriptMechanic

Reputation: 11

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

straight off the technet......

Upvotes: 1

Andy Arismendi
Andy Arismendi

Reputation: 52699

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

Upvotes: 1

Related Questions