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

Jar*_*gin 38 powershell iis-7

目前我正在尝试运行这个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"
}
Run Code Online (Sandbox Code Playgroud)

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

& .\InstallWebsite.ps1 -websiteName "MyWebsite" -physicalPath "C:\TEST\MyWebsite"
Run Code Online (Sandbox Code Playgroud)

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

start-website "$websiteName"
Run Code Online (Sandbox Code Playgroud)

当该命令运行时,我收到以下错误,我无法成功排除故障:

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
Run Code Online (Sandbox Code Playgroud)

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

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"
}
Run Code Online (Sandbox Code Playgroud)

我使用以下命令运行它:

& .\UninstallWebsite.ps1 -websiteName "MyWebsite" -appPoolname "MyWebsite"
Run Code Online (Sandbox Code Playgroud)

Kev*_*Kev 65

错误消息:

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

...通常意味着你有一个绑定冲突,其中已经有一个站点在同一个IP地址,端口上运行,如果你正在使用它们,主机头.

我将检查IIS MMC中的新站点绑定,然后查明是否有其他东西使用完全相同的绑定.