近期由于新上架一批Windows平台服务器,并加入负载均衡中使用,故每台服务器上的IIS部署一致,如果在每台服务器上去重复操作是一项很烦人的事儿,结合之前部署的puppet及mco在Puppet服务端将脚本和要用到的程序及文件部署到Files目录下 利用MCO直接推送到新上架的服务器中进行部署和并执行脚本,现就将其建立IIS站点部署这一部分脚本共享给大家,其中有什么不足之处,还请大牛们多多指教:

# ************************************************************
# *                                                          *
# *                 Powershell部署IIS脚本                    *
# *                                                          *
# ************************************************************
# 作者:网上管家婆运维工程师--Sanddy QQ:442405
# 日期:2014-06-02
#set-executionpolicy remotesigned
Import-Module WebAdministration  #导入IIS模块
# 建立IIS站点所用参数(修改以下参数可以建立不同的站点)
#################################################################################################
$sitePort = 80  #端口
$SiteName = "test"    #站点名
$SiteAppPools = $SiteName  #进程池名
$SiteAppPoolsModel = "Classic"  #进程池使用通道模式
$AppPoolType = "Network Service"        #指定应用程序池要使用的帐户标识(0 >Local Service 1 >Local System  2 >Network Service  3 >User 4 >ApplicationPoolIdentity)
$managedRuntimeVersion = "v4.0"  #.net版本
$WebSitePath = "D:\OM_WebSite\Test" #站点程序路径
$HostHeader1 = "test.test.com.cn"      #绑定站点域名
$HostHeader2 = "test.test.com"      #绑定站点域名
$defaultDocument = "Default.html"
$IISLogFile = "d:\LogFiles\$SiteName" #IIS日志路径
$net32Or64 = $true  #是否启用.net32模式#################################################################################################
#创建IIS应用程序池
function BuildAppPool(){$AppPool = "iis:\AppPools\" + $SiteAppPools$existAppPool = Test-Path $AppPoolif($existAppPool -eq $false){#创建应用程序池.$Env:windir\system32\inetsrv\appcmd.exe add apppool /name:$SiteAppPools /managedRuntimeVersion:$managedRuntimeVersion  /managedPipelineMode:$SiteAppPoolsModel#指定应用程序池要使用的帐户标识.$Env:windir\system32\inetsrv\appcmd.exe set config /section:applicationPools /[name="'$SiteAppPools'"].processModel.identityType:NetworkService#设置应用程序池使用.net版本.$Env:windir\system32\inetsrv\appcmd.exe add apppool /name:$SiteAppPools /managedRuntimeVersion:$managedRuntimeVersion  /managedPipelineMode:$SiteAppPoolsModel#限制进程使用内存上限为1.5G.$Env:windir\system32\inetsrv\appcmd.exe set config /section:applicationPools /[name="'$SiteAppPools'"].recycling.periodicRestart.privateMemory:1572864#指定进程固定回收时间.$Env:windir\system32\inetsrv\appcmd.exe set apppool /apppool.name: $SiteAppPools /recycling.periodicRestart.time:1.00:00:00#启用.net32模式.$Env:windir\system32\inetsrv\appcmd.exe set config /section:applicationPools /[name="'$SiteAppPools'"].enable32BitAppOnWin64:$net32Or64#是否自动启动.$Env:windir\system32\inetsrv\appcmd.exe set config /section:applicationPools /[name="'$SiteAppPools'"].autoStart:$true}
}#创建IIS应用站点
function BuildSite(){$appSitePath = "iis:\sites\"+$SiteName$existweb = Test-Path $appSitePathif(!$existweb){New-Website -name $SiteName -port $sitePort  -ApplicationPool $SiteAppPools -PhysicalPath $WebSitePath.$Env:windir\system32\inetsrv\appcmd.exe set site $SiteName /bindings:"http/*:80:$HostHeader1,http/*:80:$HostHeader2".$Env:windir\system32\inetsrv\appcmd.exe set config /section:directoryBrowse /enabled:false    }else{echo "'$SiteName' is Already exists"}
}#设置IIS日志记录路径
function CreatIISLogFile(){.$Env:windir\system32\inetsrv\appcmd.exe set site $SiteName "-logfile.directory:$IISLogFile"
}#为F5设备创建ISPAI筛选器
function CreatISP(){$x = [string](.$Env:windir\system32\inetsrv\appcmd.exe list config $SiteName /section:isapiFilters)if ($x -like "*F5XForwardedFor*"){echo "isapiFilters is Already exists"}else{.$Env:windir\system32\inetsrv\appcmd.exe unlock config $SiteName "-section:system.webServer/isapiFilters".$Env:windir\system32\inetsrv\appcmd.exe set config $SiteName /section:isapiFilters /"+[name='F5XForwardedFor',path='$Env:windir\System32\F5XForwardedFor.dll',enabled='true']"}
}function RunBuild(){BuildAppPoolBuildSite    CreatIISLogFileCreatISP.$Env:windir\system32\inetsrv\appcmd.exe start site $SiteName
}
RunBuild

转载于:https://blog.51cto.com/starlight/1425210

利用PowerShell脚本部署IIS站点相关推荐

  1. 使用PowerShell脚本部署定时器到MOSS2010(原创)

    第一章 前言 在此次练习中,您将了解到如何使用PowerShell和使用SharePoint 2010构建的PowerShell加载项.我这里使用Windows PowerShell ISE来编辑Po ...

  2. 利用Powershell自动部署asp.net mvc网站项目 (一)

    这一篇中我们会写一些关于自动化部署的代码.我们会使用 Powershell 书写这类代码. 你将发现这篇文章中涉及的东西非常具体,有的要求甚至相当苛刻且可能不具有通用性.这是因为部署从来都是跟环境打交 ...

  3. 利用PowerShell进行数据库部署冒烟测试

    PowerShell是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能,也可以调用Azure.在Win10里面附带PowerShell V5,Po ...

  4. Windows Azure Cloud Service (23) 使用Full IIS模式部署多站点和虚拟目录

    <Windows Azure Platform 系列文章目录> 本章我们将介绍如何使用Windows Azure的Full IIS模式部署多站点和虚拟目录. 首先我们先新建一个Window ...

  5. SharePoint自动化部署,利用PowerShell 导入用户至AD——PART II

    这是对上一篇文章<SharePoint自动化部署,利用PowerShell 导出/导入AD中的用户>进行补充.开发时,为了测试和演示,我们往往需要经常性的把用户添加到AD中.数据量小的时候 ...

  6. bat脚本交互输入_测评 | 不使用powershell运行 PowerShell 脚本的工具汇总

    不使用 powershell.exe 的情况下,可以运行 powershell 脚本和命令么? 可以的! 本文总结了6款可直接运行 powershell 脚本和命令的工具,献给所有的渗透测试人员和红队 ...

  7. 如何利用Gitlab-CI持续部署到远程机器?

    长话短说,今天聊一聊使用Gitlab-CI 自动部署到远程服务器. 如果看过<基于docker-compose的Gitlab CI/CD实践&排坑指南>这篇文章的朋友,会注意到我是 ...

  8. winexec函数 执行powershell 脚本_丢掉 Powershell.exe 来渗透测试

    0x00 前言 作为一个 pentest,真的是不需要 Powershell 吗?如果是,我真的会觉得不可思议. 但是,如果是因为某些策略,阻止了你对 powershell.exe 的访问,那该怎么办 ...

  9. Windows Server 2003 部署IIS、部署DNS,Windows Server 2003搭建网站,实现同网段主机访问网站

    zWinserver 2003部署网站步骤: 目的: 让winserver 2003做网站服务器,接着再继续部署dns,让该服务器也做dns服务器,要想让同网段也访问得到该dns服务器域名解析后的网站 ...

最新文章

  1. 马云再谈996,又一次被网友怒骂:马老师,求求你闭嘴吧!
  2. 登白云嶂,银屏嘴游记
  3. 浏览器本地存储简单了解一下
  4. ABAP development tools实现原理介绍
  5. JAVA的面向对象编程--------课堂笔记
  6. P2633 Count on a tree
  7. MFC中打开文件对话框:CFileDlg
  8. linux内存手动释放
  9. 使用XmlWriter写XML文件
  10. Unity基础:简易道具生成
  11. POI excel添加数据有效性验证以及解决DataValidation超长的问题
  12. 线程池ThreadPoolExecutor与ForkJoinPool
  13. 迅捷路由虚拟服务器设置,迅捷 FWR310 无线路由器端口映射设置指南
  14. docker基础操作
  15. SDL入门教程(七):SDL抠色(Color Keying)
  16. linux启用dcb步骤,Linux内核DCB子系统
  17. 闪存中的NorFlash、NandFlash及eMMC三者的区别
  18. c++的*号是否有空格的区别以及char*转std::vector<float>解析
  19. 平安科技面试问题整理
  20. Fluent UDF 根据给定点坐标获取cell

热门文章

  1. Sigrity PowerDC仿真
  2. 人工智能入门-R语言数据分析与数81
  3. vue-quill-editor富文本编辑器及图片上传到服务器
  4. 【mysql5.1.47会报一个时间戳设置未null的错】
  5. ubuntu下hadoop运行wordcount程序
  6. sap 物料标准价和移动平均价差异
  7. 爱奇艺大裁员,你怎么看…
  8. 建立更好的性能评估系统步骤3,确定平台供应商
  9. 千元机和GTA之间,只差一个超级游戏
  10. android之实现带图片和文本的Button