Powershell腳本部署打好的Website zip包並重啓IIS

直接上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;


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章