PowerShell自动部署IIS站点(Windows Server 2008 R2)
1、功能描述
1. 连接软件源服务器下载.NET Framework 4.0、.NET Framework 4.5。
2. 检测并判断当前.NET Framework版本是否小于v4.0,如果小于则进行升级。
3. 安装IIS组件,安装完成后删除软件及脚本。
在升级.NET Framework时,是先从3.5升级(可以通过执行命令"Add-WindowsFeature As-Net-Framework"直接安装3.5),然后依次升级4.0、4.5。
2、实现
源码如下:
- try {
- Import-Module ServerManager -ErrorAction Stop
- Import-Module BitsTransfer -ErrorAction Stop
- }
- catch {
- Write-Warning "$_"; exit
- }
- $packages_path = "D:\software" # Packages storage directory
- function Download() {
- $isExists = Test-Path $packages_path
- if(!$isExists) {
- New-Item -ItemType Directory $packages_path
- }
- # instantiate a socket object,
- # Try connect to download the source
- $testConn = New-Object Net.Sockets.TcpClient
- $testConn.Connect("$address", 80) # $address need to custom
- if($testConn) {
- Start-BitsTransfer $address/dotnet4.0.exe $packages_path
- Start-BitsTransfer $address/dotnet4.5.exe $packages_path
- return $true
- } else {
- return $false
- }
- }
- function CheckVersion {
- # To detect the .NET Framework whether exists in the registry
- $isExists = Test-Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\"
- if(!$isExists) {
- return $false
- } else {
- # Returns the current .NET Framework version
- $version = gci "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP" | sort pschildname -desc | select -fi 1 -exp pschildname
- return $version
- }
- }
- function Update {
- Add-WindowsFeature As-Net-Framework # Update .NET Framework 3.5
- # The first cycle:
- # Perfrom CheckVersion function, returns the value assigned to $response
- # If $response < 4.0, start install dotnet 4.0 and dotnet 4.5
- # Enter the second loop
- # The second cycle:
- # Again to perfrom CheckVersion function
- # If the installation is successful,
- # the value of variable $response at this time will be greater than 4.0,
- # the output corrent .NET Framework version and returns $true
- for($i=0;$i -lt 2;$i++) {
- $response = CheckVersion
- if($response -lt "v4.0") {
- Start-Process -Wait $packages_path\dotnet4.0.exe -ArgumentList "/quiet"
- Start-Process -Wait $packages_path\dotnet4.5.exe -ArgumentList "/quiet"
- } else {
- Write-Host "DotNET current version is: $response"
- return $true
- }
- }
- # Above cycle without entering the return statement,
- # then .NET Framework update failed, this function will return the $false
- return $false
- }
- function Install {
- $features = Get-WindowsFeature Web-Server,Web-Static-Content,Web-Default-Doc,Web-Http-Errors,Web-Http-Redirect,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Http-Logging,Web-Request-Monitor,Web-Filtering,Web-IP-Security,Web-Stat-Compression,Web-Mgmt-Console,Web-WHC
- # Install IIS features
- foreach($item in $features) {
- Add-WindowsFeature $item
- }
- Remove-WindowsFeature Web-Dir-Browsing # Delete "Web-Dir-Browsing" function
- }
- function Registry {
- $is64bit = [IntPtr]::Size -eq 8 # To determine whether a system is 64-bit
- $isapiPath_32 = "$env:windir\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
- Set-Location "$env:windir\Microsoft.NET\Framework\v4.0.30319\"; .\aspnet_regiis.exe -i
- if($is64bit) {
- $isapiPath_64 = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
- Set-Location "$env:windir\Microsoft.NET\Framework64\v4.0.30319\"; .\aspnet_regiis.exe -i
- }
- }
- try {
- $chkGet_result = Download
- $chkUp_result = Update
- if($chkUp_result) {
- Install; Registry
- } else {
- Write-Warning "Update .NET Framework error."
- }
- }
- catch {
- Write-Warning "$_"; exit
- }
- finally {
- Remove-Item $packages_path -Recurse
- Remove-Item $MyInvocation.MyCommand.Path -Force
- }
PowerShell自动部署IIS站点(Windows Server 2008 R2)的更多相关文章
- Windows Server 2008 R2 + IIS 环境部署Asp.Net Core App
Windows + IIS 环境部署Asp.Net Core App 环境:Windows Server 2012, IIS 8, Asp.Net Core 1.1. 不少人第一次在IIS中部署A ...
- 在Windows Server 2008 R2上安装IIS服务
一.Windows Server 2008 R2 介绍 1.Windows Server 2008 R2 基本概念 2.Windows Server 2008 R2 家族系列 二.VMware虚拟机安 ...
- Windows Server 2008 R2之一活动目录服务部署
测试环境: 服务器:计算机名Win2008R2CNDC,已安装Windows Server 2008 R2.IPV4:192.168.1.13,255.255.255.0,网关地址192.168.1. ...
- SQLite 在Windows Server 2008 R2 部署问题FAQ汇总[轉]
轉自:http://www.steveluo.name/sqlite-windows-server-2008-r2-deploy-faq/ 今天花了一天的时间研究了一下SQLite,以取代一些轻量级项 ...
- windows server 2008 R2 Enterprise 间实时同步之FreeFileSync 部署过程
WindowsServer间实时同步之FreeFileSync 部署过程 1. 实验主机信息 IP 操作系统 源目录 目标目录 10.155.0.80 Windows Server 2008 R2 D ...
- windows server 2008 R2域中的DC部署 分类: AD域 Windows服务 2015-06-06 21:09 68人阅读 评论(0) 收藏
整个晚上脑子都有点呆滞,想起申请注册好的博客还从来都不曾打理,上来添添生机.从哪里讲起呢,去年有那么一段时间整个人就陷在域里拔不出来,于是整理了一些文档,害怕自己糊里糊涂的脑子将这些东西会在一觉醒来全 ...
- windows server 2008 R2中建立ftp站点
在windows server 2008 R2中建立ftp站点,要遵循以下步骤: (1) 开启IIS中的ftp服务: (2) 在IIS中建立ftp站点. 具体过程如下: (1) 开启IIS中的ftp服 ...
- Windows Server 2008 R2 部署服务
Windows Server 2008 R2 部署服务 部分参考: Windows Server 2008 R2 部署服务 - 马睿的技术博客 - 51CTO技术博客http://marui.blog ...
- Windows Server 2008 R2 IIS7.5 部署 MVC HTTP 404.0 Not Found 错误
如图 在Windows Server 2008 R2 IIS7.5 部署 MVC HTTP 404.0 Not Found 错误,在Win7环境下测试正常,在百度中查找相关解决方法,如修改配置文件等, ...
随机推荐
- Oracle Sales Cloud:管理沙盒(定制化)小细节1——利用公式创建字段并显示在前端页面
Oracle Sales Cloud(Oracle 销售云)是一套基于Oracle云端的CRM管理系统.由于 Oracle 销售云是基于 Oracle 云环境的,它与传统的管理系统相比,显著特点之一便 ...
- Java中的经典算法之冒泡排序(Bubble Sort)
Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一 ...
- 20-C语言结束
我回去看了下5号写的.虽然今天已经21号了~,花了16天. 复习完C专题,接下来我大概会用C做一些操作系统/信息安全的小东西,会发到博客里,敬请期待! ----2016/11/21
- mac终端命令
目录操作 命令名 功能描述 使用举例 mkdir 创建一个目录 mkdir dirname rmdir 删除一个目录 rmdir dirname mvdir 移动或重命名一个目录 mvdir dir1 ...
- 【转】JVM 架构解读
每个Java开发人员都知道字节码由JRE(Java运行时环境)执行.但许多人不知道JRE是Java Virtual Machine(JVM)的实现,它分析字节码,解释代码并执行它.作为开发人员,我们应 ...
- [python]set集合学习
python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...
- mysql max_allowed_packet 设置过小导致记录写入失败
mysql根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会受max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Bulb Switcher 灯泡开关
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
- [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...