目前我正在尝试运行这个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"