WMI/PowerShell Bug:为什么 CreateSite 突然创建*两个*站点?

发布于 2024-07-09 12:14:43 字数 824 浏览 4 评论 0原文

我有一个简单的 PowerShell 脚本,它使用 WMI 在 Vista 机器上创建一个网站。 是的,我知道 PowerShell 有一个可与 IIS 7 配合使用的 IIS 提供程序,但此脚本还必须支持 IIS 6.0,因此排除了这种情况。

不管怎样,脚本运行得很好,但突然之间(我的意思是,我对脚本进行了零代码更改),它开始为每次调用 CreateNewSite 方法创建第二个损坏的站点。 下面是脚本。 有人有主意吗?

$path = "C:\My Path\WebSite"
$site = "TestSite"
$hostHeader = "demo.blah.com"

$service = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebService"

$bindingClass = [wmiclass]'root\MicrosoftIISv2:ServerBinding'
$bindings = $bindingClass.CreateInstance()
$bindings.IP = ""
$bindings.Port = "80"
$bindings.Hostname = $hostHeader

$result = $service.CreateNewSite($site, $bindings, $path)

上面的脚本只是创建了一个名为“TestSite”的站点,但现在它还创建了一个名为“SITE_1786339847”的站点(数字发生了变化,但始终与此类似)。 我已经逐步执行一次一行的脚本,并且在调用 CreateNewSite 方法之前都不会创建两个站点。 WMI 只是有问题吗?

I have a simple PowerShell script that uses WMI to create a web site on a Vista box. Yes, I know PowerShell has an IIS provider for working with IIS 7, but this script must also support IIS 6.0, so that rules that out.

Anyway, the script was working just fine, but all of the sudden (and I mean that literally, I made zero code changes to the script) it started creating a second, broken site for every call to the CreateNewSite method. Below is the script. Anyone have any ideas?

$path = "C:\My Path\WebSite"
$site = "TestSite"
$hostHeader = "demo.blah.com"

$service = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebService"

$bindingClass = [wmiclass]'root\MicrosoftIISv2:ServerBinding'
$bindings = $bindingClass.CreateInstance()
$bindings.IP = ""
$bindings.Port = "80"
$bindings.Hostname = $hostHeader

$result = $service.CreateNewSite($site, $bindings, $path)

The above script was just creating a site named 'TestSite', but now it's also creating a site called 'SITE_1786339847' (the number changes, but it's always similar to that). I have stepped through the script executing one line at a time, and neither site is created until the CreateNewSite method is invoked. Is WMI just buggy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

り繁华旳梦境 2024-07-16 12:14:43

哎呀,回答了我自己的问题。 我检查了原始 IIS 7.0 配置文件,发现一个孤立的虚拟目录与 ID 为 1786339847 的站点关联。当我从配置文件中删除该虚拟目录时,脚本再次开始正常工作。

如果有人遇到类似情况,请在删除之前从 IIS 管理器中获取不良站点的站点 ID,然后打开 C:\Windows\system32\inetsrv\config\applicationHost.config。 扫描文件中的该 ID 并查找对其的任何孤立引用。 首先确保您有备份。

Whoops, answered my own question. I checked the raw IIS 7.0 configuration file and found an orphaned virtual directory that was associated to a site with the ID 1786339847. When I removed that virtual directory from the configuration file, the script started working correctly again.

In case anyone runs into something similar, grab the site ID for the bad site from IIS Manager before deleting it, then open up C:\Windows\system32\inetsrv\config\applicationHost.config. Scan the file for that ID and look for any orphaned references to it. Be sure you have a backup first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文