使用Powershell更新IIS中的主机头 [英] Update Host Header in IIS with Powershell

查看:61
本文介绍了使用Powershell更新IIS中的主机头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:使用Powershell更新IIS7.5站点的现有主机头

Goal: Update an existing host header for an IIS7.5 site with powershell

问题:Set-WebBinding需要我没有的站点名称.我确实有HostHeader.

Problem: Set-WebBinding requires the name of the site which I don't have. I do have the HostHeader though.

场景:我在IIS中有多个站点.其中一些具有主机标头,其中包含我要更改的特定字符串.

Scenario: I have multiple sites in IIS. Some of them have a host header with a particular string that I want to change.

Site1 - site1.stuff.domain.net
Site2 - site2.stuff.domain.net
Site3 - site3.domain.net

我要更改标题中具有.stuff的所有网站.

I want to change all sites that have .stuff in their headers.

我正在使用Get-WebBinding来获取所有站点及其绑定的列表.然后,我遍历它们并检查bindingInformation是否包含.stuff.我以自己喜欢的方式修改了字符串,然后用

I'm using Get-WebBinding to get a list of all sites and their bindings. I then loop through them and check if bindingInformation contains .stuff. I modify the string how I please and then go to update the header with

Set-WebBinding -HostHeader $originalHeader -SetProperty HostHeader -Value $newHeader

但是,显然,要使用Set-WebBinding,必须具有站点名称,而Get-WebBinding与允许您基于HostHeader(Get-WebBinding -HostHeader $someValue)进行绑定的方式不同.有没有一种方法可以使用Set-WebBinding而不指定站点的Name?有没有办法从Get-WebBinding获取网站名称? Set-WebBinding可以替代吗?还是有更好的方法来做我想做的事情?

Apparently though, you have to have the site's name in order to use Set-WebBinding, unlike Get-WebBinding which allows you to get a binding based on the HostHeader (Get-WebBinding -HostHeader $someValue). Is there a way to use Set-WebBinding without specifing the Name of a site? Is there a way I can get the site's name from Get-WebBinding? Is there an alternative to Set-WebBinding? Or is there a better way to do what I'm trying to do?

推荐答案

尝试一下:

Get-WebBinding -HostHeader *.stuff.* | Foreach-Object{
    #$NewHeader = $_.bindingInformation -replace '\.stuff\.','.staff.'
    Set-WebConfigurationProperty -Filter $_.ItemXPath -PSPath IIS:\ -Name Bindings -Value @{protocol='http';bindingInformation=$NewHeader}
}

这篇关于使用Powershell更新IIS中的主机头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆