直接上Power腳本:
#Get current path
$CurrentDir = $( pwd );
#Get MSDeploy path
Write-Host "Getting MsDeploy path...";
[int]$MaxMsDeployVersion = 0;
$MsDeployVersions = $(Get-Item "HKLM:SOFTWARE\Microsoft\IIS Extensions\MSDeploy\*");
[int]$MaxMsDeployVersion = 0;
foreach ($Ver in $MsDeployVersions)
{
$LastSlash = $Ver.Name.LastIndexOf( "\" );
[int]$ThisNumber = $Ver.Name.Substring( $LastSlash + 1 );
# For debug only:
# Write-Log "Last slash position = [$LastSlash]; this version # = [$ThisNumber]";
if ( $ThisNumber -ge $MaxMsDeployVersion )
{
$MaxMsDeployVersion = $ThisNumber;
}
}
$MsDeployPath = $( Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\$MaxMsDeployVersion" ).InstallPath;
#Go to the path where the MSDeploy at.
Set-Location $MsDeployPath ;
#Get the parameters file for the web site.
[string]$WebSvcParamsFile = "$CurrentDir\WebSite\Parameters.xml"
Write-Host "Deploying the Web site...";
[string]$Result = $(.\MsDeploy.exe -verb:Sync -source:package="$CurrentDir\WebSite\Web.zip" -dest:auto -setParamFile:"$WebSvcParamsFile" -enableLink:AppPoolExtension -verbose -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension);
Write-Host "MsDeploy completed; output follows:";
Write-Host $Result;
Write-Host "Successful completion!";
#=======================================
# Reset IIS on the server
#=======================================
Write-Host "Restarting IIS Services...";
iisreset /noforce;