12

I am trying to add an MSMQ binding for my IIS Web Site, correct binding should look like this:

enter image description here

So I am executing following line in PowerShell:

New-WebBinding -Name "My Site"  -Protocol net.msmq -HostHeader "localhost"

and it creates the following binding:

enter image description here

prefixing it with *:80:, so my MSMQ messages don't get picked up by WCF service. Maybe I am doing it wrong? How to create a binding with Binding Information set to just "localhost" using this PowerShell comandlet?

Commandlet codumentaiton can be found here.

Restuta
  • 5,855
  • 33
  • 44

3 Answers3

8

Looking at the decompiled code of the cmdlet, looks like it adding the IPAddress and Port information in the binding and there is no workaround to it.

Relevant sections from the code:

private string ipAddress = "*";
...
builder.Append(this.ipAddress);
...
builder.Append(":" + this.sitePort.ToString(CultureInfo.InvariantCulture) + ":");

But you can do what the cmdlet actually does ( below code from cmdlet):

new-itemproperty -path "IIS:\sites\test" -name bindings -value @{protocol="net.msmq"; bindingInformation="localhost"}
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Oh, could you please tell me how to decompile cmdlets? Thanks. – Restuta Feb 24 '12 at 17:46
  • @Restuta Checkout [ILSpy](http://wiki.sharpdevelop.net/ILSpy.ashx) and [dotPeek](http://www.jetbrains.com/decompiler/). – Andy Arismendi Feb 24 '12 at 17:55
  • I know about them, but what assembly do I need to decombile? – Restuta Feb 24 '12 at 18:33
  • @Restuta Depends, but most are in `Microsoft.PowerShell.Commands`. Browse around in `System.Management.Automation`. – Andy Arismendi Feb 24 '12 at 18:56
  • @Restuta - look at `$pshome\Modules\WebAdministration\Microsoft.IIS.PowerShell.Provider.dll` – manojlds Feb 24 '12 at 20:14
  • @Restuta For snap-ins you can do: `get-pssnapin -Name WebAdministration | select *`. Look at `ModuleName`. Also check out the rest: `get-pssnapin | Select ModuleName`. – Andy Arismendi Feb 24 '12 at 21:11
  • @Restuta Another way is: `(get-command $cmdletName).DLL` e.g. `(get-command New-WebBinding).DLL`. – Andy Arismendi Feb 25 '12 at 19:52
  • I keep getting the following error when doing the new-itemproperty way: New-ItemProperty : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'. This appears to be on the -value parameter I think. Anyone get similar problems? – Nestor Dec 02 '13 at 23:57
2

Give this a try:

New-ItemProperty "IIS:\sites\NameOfYourSite" -name bindings -value @{protocol="net.msmq";bindingInformation="localhost"}
Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124
  • I keep getting the following error when doing the new-itemproperty way: New-ItemProperty : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'. This appears to be on the -value parameter I think. Any suggestions? – Nestor Dec 02 '13 at 23:58
  • @Acquire hmm should work, did you import the webadministration module? – Andy Arismendi Dec 03 '13 at 01:58
0

If your are running PowerShell (Core), a.k.a PowerShell >v7.1.x, you will find yourself in trouble because...

WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session;
please note that all input and output of commands from this module will be deserialized objects.
If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

The IIS provider isn't available via remoting session.

The easiest trick is to redirect string via pipeline to Windows PowerShell.

"Import-Module WebAdministration;New-ItemProperty -Path `"IIS:\Sites\$($configuration.Website.Name)`" -Name Bindings -value @{protocol = `"net.msmq`"; bindingInformation = `"localhost`" }" | PowerShell

In this example, the website name is read from the configuration JSON. You can replace it by a hard-coded site name.

KUTlime
  • 5,889
  • 1
  • 18
  • 29