您的位置:首页 > 运维架构 > Shell

Powershell脚本部署打好的Website zip包并重启IIS

2012-10-19 10:32 211 查看
直接上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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: