“无法创建文件”在Powershell中运行Start-Website命令时出错 [英] "Cannot create a file" error when running Start-Website command in Powershell

查看:527
本文介绍了“无法创建文件”在Powershell中运行Start-Website命令时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试运行此PowerShell脚本:

Currently I'm trying to run this powershell script:

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"
}

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

I use the following command to run the script:

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

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

Everything works fine, except for the last command inside of the if statement:

start-website "$websiteName"

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

When that command runs, I receive the following error, which I haven't been able to successfully troubleshoot:

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

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

I also have the following script to remove the website if it matters:

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"
}

我使用以下命令运行它:

I run it with the following command:

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


推荐答案

错误消息:


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

Start-Website : Cannot create a file when that file already exists.

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

...usually means that you have a bindings conflict where there is already a site running on the same IP address, port and if you're using them, host header.

我会在IIS MMC中检查你的新网站绑定,然后找出其他东西是否正在使用完全相同的绑定。

I'd check your new site bindings in IIS MMC then find out if something else is using exactly the same bindings.

这篇关于“无法创建文件”在Powershell中运行Start-Website命令时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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