前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IIS自动发布脚本

IIS自动发布脚本

作者头像
Vincent-yuan
发布2020-11-12 11:25:16
1.5K0
发布2020-11-12 11:25:16
举报
文章被收录于专栏:Vincent-yuanVincent-yuan

目的:使用powershell脚本的方式实现自动化在iis部署网站的功能。

1.使用管理员身份运行powershell

2.脚本如下

auto_iis_deploy.ps1

代码语言:javascript
复制
#iis自动部署脚本
param(
    [string]$siteName = "default",
    [string]$port = "80"
)

Write-Host "siteName:$siteName,port:$port"
$physicalPath="d:\www\$siteName"

Import-Module WebAdministration
Write-Host "Setting up IIS"

if(!(Test-Path $physicalPath))
{
    mkdir $physicalPath
}

#创建站点
Write-Host "create or update site.."
if((Test-Path IIS:\Sites\$siteName))
{
    Remove-Website $siteName
}
New-Website -Name $siteName -PhysicalPath $physicalPath -ApplicationPool $siteName -Port $port -ErrorAction Stop

#创建应用程序池
Write-Host "create appPool or next step.."
if(!(Test-Path IIS:\AppPools\$siteName))
{
    New-Item -path IIS:\AppPools\$siteName
}
Set-ItemProperty IIS:\AppPools\$siteName managedRuntimeVersion v4.0

#停止应用程序池
Write-Host "stop appPool"
$appPool=Get-WebAppPoolState -Name $siteName
if($appPool -eq "Started")
{
    Stop-WebAppPool -Name $siteName
}

#解压文件
#Write-Host "unzip the source file"
#$sourceFile=$siteName+".zip"
#[System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile,$siteName)

#启动网站
Write-Host "start website"
Start-Website -Name $siteName

#启动应用程序池
Write-Host "start webAppPool"
Start-WebAppPool -Name $siteName

Write-Host "$siteName successfully started"

这里设置的是一个空站点,可以自己设置文件路径;这里的路径是 $physicalPath 变量的值。

3.运行脚本

代码语言:javascript
复制
.\auto_iis_deploy.ps1 -siteName myWeb -port 8083

4.效果图

参考网址:

https://cloud.tencent.com/developer/article/1462776

https://cloud.tencent.com/developer/article/1047718

https://docs.microsoft.com/en-us/powershell/module/webadministration/?view=win10-ps

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-11-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档