0
我需要檢查IIS中是否存在站點。如果退出,那麼我需要執行PS腳本,如果沒有,那麼我需要創建一個新名稱的IIS網站並執行PS腳本。檢查IIS網站是否存在並將項目複製到物理路徑
我在這裏寫了一些東西,但造成了很少的錯誤。
Import-Module WebAdministration
Function WAPublish
{
Param(
[parameter(Mandatory=$true)]
[String]
$RELEASEDIR,
[parameter(Mandatory=$true)]
[String]
$DESTINATION,
[parameter(Mandatory=$true)]
[String]
$SERVER,
[parameter(Mandatory=$true)]
[String]
$SITE
)
if(Test-Path IIS:\Sites\$site)
{
Write-Host "The provided website name is $site and it is a valid website`r`n" -ForegroundColor Cyan
Get-ChildItem "$RELEASEDIR\*"
Copy-Item "$RELEASEDIR\*" "\\$SERVER\$DESTINATION" -Force -Recurse
Write-Host "Deployment completed"
invoke-command -computername "$SERVER" -scriptblock {iisreset /RESTART}
}
else
{
Write-Host "There is not a website present in the name provided`r`n" -ForegroundColor Red
New-Website –Name $SITE –PhysicalPath "$DESTINATION"
if ($error) { exit 1 }
Get-ChildItem "$RELEASEDIR\*"
Copy-Item "$RELEASEDIR\*" "\\$SERVER\$DESTINATION" -Force -Recurse
Write-Host "Deployment completed"
invoke-command -computername "$SERVER" -scriptblock {iisreset /RESTART}
Exit
}
if ($error) { exit 1 }
}
WAPublish -RELEASEDIR "C:\Location" -DESTINATION "c$\test" -SERVER "server" -SITE "test"
錯誤
New-Website : Parameter 'PhysicalPath' should point to existing path.
At C:\Release\RPCPS\WebApiPublish-2.ps1:29 char:9
+ New-Website –Name $SITE –PhysicalPath "$DESTINATION"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-Website], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.IIs.PowerShell.Provider.NewWebsiteCommand
我仍然收到同樣的錯誤。 新網站:參數'PhysicalPath'應指向現有路徑。 在C:\ Release \ RPCPS \ test.ps1:34 char:13 + New-Website -Name $ SITE -PhysicalPath「$ DESTINATION」 + ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [新網站] ,ArgumentException + FullyQualifiedErrorId:System.ArgumentException,Microsoft.IIs.PowerShell.Provider.NewWebsiteCommand – Kally
$ DESTINATION的值是什麼? –