Why Powershell's New-WebBinding commandlet creates incorrect HostHeader?

后端 未结 3 1445
无人共我
无人共我 2021-01-17 12:08

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

\"enter

相关标签:
3条回答
  • 2021-01-17 12:45

    Give this a try:

    New-ItemProperty "IIS:\sites\NameOfYourSite" -name bindings -value @{protocol="net.msmq";bindingInformation="localhost"}
    
    0 讨论(0)
  • 2021-01-17 12:46

    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"}
    
    0 讨论(0)
  • 2021-01-17 12:54

    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.

    0 讨论(0)
提交回复
热议问题