Search code examples
iispowershelliis-7.5msmq

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?


Solution

  • 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