在 Powershell 中运行 Start-Website 命令时出现“无法创建文件”错误

2024-01-11

目前我正在尝试运行这个 powershell 脚本:

Param (
    $websiteName,
    $physicalPath
)

import-module WebAdministration
$website = get-website | where-object { $_.name -eq "$websiteName" }
if($website -eq $null){
    New-webapppool -Name "$websiteName"
    Set-WebConfiguration -filter "/system.applicationHost/applicationPools/add[@name='$websiteName']" -PSPath IIS:\ -value (@{managedRuntimeVersion="v4.0"})
    New-website -Name "$websiteName" -PhysicalPath "$physicalPath" -ApplicationPool "$websiteName"
    start-website "$websiteName"
}

我使用以下命令来运行脚本:

& .\InstallWebsite.ps1 -websiteName "MyWebsite" -physicalPath "C:\TEST\MyWebsite"

一切正常,除了 if 语句中的最后一个命令:

start-website "$websiteName"

当该命令运行时,我收到以下错误,但我无法成功解决该错误:

Start-Website : Cannot create a file when that file already exists. (Exception from HRESULT: 0x800700B7)
At line:1 char:14
+ start-website <<<<  "MyWebsite"
    + CategoryInfo          : InvalidOperation: (:) [Start-Website], COMException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.IIs.PowerShell.Provider.StartWebsiteCommand

如果重要的话,我还有以下脚本来删除该网站:

Param (
    $websiteName,
    $appPoolName
)

import-module WebAdministration
$website = get-website | where-object { $_.name -eq "$websiteName" }
if($website -ne $null){
    remove-website -Name "$websiteName"
    remove-webapppool -Name "$websiteName"
}

我使用以下命令运行它:

& .\UninstallWebsite.ps1 -websiteName "MyWebsite" -appPoolname "MyWebsite"

错误信息:

Start-Website :当文件已存在时无法创建该文件。

...通常意味着您存在绑定冲突,其中已经有一个站点在相同的 IP 地址、端口以及主机标头(如果您正在使用它们)上运行。

我会检查 IIS MMC 中的新站点绑定,然后查明其他内容是否使用完全相同的绑定。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Powershell 中运行 Start-Website 命令时出现“无法创建文件”错误 的相关文章

随机推荐