目前,我试图运行此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"