RSS

how to 全自动完成exchange 2010的preinstall准备

23 Nov

之前老G曾经发出一声感慨,难道powershell就不能全自动完成exchange 2010的preinstall准备?我当时的回答就是“NO!”可能我小看powershell的能力了!

下面这个脚本,会自动完成installfilterpack的下载以及安装过程。可耐么?

——————

Function InstallFilterPack()
{
$folderPath = 'C:\Temp'
    if (test-path $folderpath)
        {
        Write-Host "The folder $folderPath exists."
        } 
    else
        {
        Write-Host "The folder $folderPath does not exist, it will be created."
        New-Item $folderpath -type directory | Out-Null
        } 
 
Write-Host "Downloading Microsoft Filter Pack..."
$clnt = new-object System.Net.WebClient
$url = "http://download.microsoft.com/download/b/e/6/be61cfa4-b59e-4f26-a641-5dbf906dee24/FilterPackx64.exe"
$file = $folderPath+"\FilterPackx64.exe"
$clnt.DownloadFile($url,$file)
Write-Host "Installing Microsoft Filter Pack..."
$expression = $folderPath+"\FilterPackx64.exe /quiet /norestart"
Invoke-Expression $expression
} 
 
clear
write-host
write-host Exchange Server 2010 - Pre-requisites script
write-host Please, select which role you are going to install..
write-host
write-host '1) Hub Transport' -ForegroundColor 10
write-host '2) Client Access Server' -ForegroundColor 11
write-host '3) Mailbox' -ForegroundColor 12
write-host '4) Unified Messaging' -ForegroundColor 10
write-host '5) Edge' -ForegroundColor 11
write-host '6) Typical (CAS/HUB/Mailbox)' -ForegroundColor 12
write-host '7) Client Access and Hub Transport' -ForegroundColor 10
write-host 
write-host '9) Configure NetTCP Port Sharing service' -ForegroundColor 11
write-host '10) Install 2007 Office System Converter: Microsoft Filter Pack - Only if you are installing Hub or Mailbox Server role' -foregroundColor 12
write-host 
write-host 
write-host '15) Restart the computer' -foregroundColor 10
write-host
write-host
write-host "Select an option.. [1-15]? "
$opt = read-host
Import-module ServerManager
switch ($opt)
    {
        1 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server }
        2 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy }
        3 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server}
        4 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Desktop-Experience }
        5 { Add-WindowsFeature NET-Framework,RSAT-ADDS,ADLDS }
        6 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy }
        7 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy }
        9 { Set-Service NetTcpPortSharing -StartupType Automatic }
        10 {
            write-host 'Can this server access internet?'
            write-host 'Please type (Y)es or (N)o...'
            $filtpack = read-host
            switch ($filtpack)
                {
                    Y {InstallFilterPack}
                    N {
                    Write-warning 'Please download Microsoft Filter Pack from here:' 
                    Write-warning 'Office 2007 filter pack http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=60c92a37-719c-4077-b5c6-cac34f4227cc'
                    Write-warning 'Office 2010 beta filter pack http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=49429f87-212c-4dd7-b2fa-c72837a6746b'
                    }
                }
           }
        15 { restart-computer }
        default {write-host "You haven't selected any of the available options. "}
    } 

[update] 发现了原作者的更新版,好用了一些。谢谢围观

#############################################################################
# Set-Exchange2010Prereqs.ps1
# Configures the necessary prerequisites to install Exchange 2010 on a 
# Windows Server 2008 R2 server
#
# Pat Richard, MVP
# http://ucblogs.net/blogs/exchange
# 
# 1.0 – Original script 11/27/09 based on the work of Anderson Patricio and
# Bhargav Shukla 
# 
# Dedicated blog post:
# http://www.ucblogs.net/blogs/exchange/archive/2009/12/12/Automated-prerequisite-installation-via-PowerShell-for-Exchange-Server-2010-on-Windows-Server-2008-R2.aspx
#
# Some info taken from
# http://msmvps.com/blogs/andersonpatricio/archive/2009/11/13/installing-exchange-server-2010-pre-requisites-on-windows-server-2008-r2.aspx
# http://www.bhargavs.com/index.php/powershell/2009/11/script-to-install-exchange-2010-pre-requisites-for-windows-server-2008-r2/
#############################################################################

# Detect correct OS here and exit if no match
if (-not((Get-WMIObject win32_OperatingSystem).OSArchitecture -eq '64-bit') -and (Get-WMIObject win32_OperatingSystem).Version -eq '6.1.7600'){
	Write-Host "This script requires a 64bit version of Windows Server 2008 R2, which this is not." -ForegroundColor Red -BackgroundColor Black
	Exit
}

Function InstallFilterPack(){
# future: look and see if it's already installed
# 			via registry HKLM:\Software\Microsoft\CurrentVersion\Uninstall\{95120000-2000-0409-1000-0000000FF1CE}
	trap {
		Write-Host "Problem downloading FilterPackx64.exe. Please visit http://tinyurl.com/36yrlj"
		break
	}
	#set a var for the folder you are looking for
	$folderPath = 'C:\Temp'
 
	#Check if folder exists, if not, create it
	if (Test-Path $folderpath){
		Write-Host "The folder $folderPath exists."
	} else{
		Write-Host "The folder $folderPath does not exist, creating..." -NoNewline
		New-Item $folderpath -type directory | Out-Null
		Write-Host "done!" -ForegroundColor Green
	}
 
	# Check if file exists, if not, download it
	$file = $folderPath+"\FilterPackx64.exe"
	if (Test-Path $file){
		write-host "The file $file exists."
	} else {
		#Download Microsoft Filter Pack
		Write-Host "Downloading Microsoft Filter Pack..." -nonewline
		$clnt = New-Object System.Net.WebClient
		$url = "http://download.microsoft.com/download/b/e/6/be61cfa4-b59e-4f26-a641-5dbf906dee24/FilterPackx64.exe"
		$clnt.DownloadFile($url,$file)
		Write-Host "done!" -ForegroundColor Green
	} 
	#Install Microsoft Filter Pack
	Write-Host "Installing Microsoft Filter Pack..." -nonewline
	$expression = $folderPath+"\FilterPackx64.exe /quiet /norestart"
	Invoke-Expression $expression
	Start-Sleep -Seconds 10
	write-host "done!" -ForegroundColor Green	
}

Function SetRunOnce(){
	# Sets the NetTCPPortSharing service for automatic startup before the first reboot
	# by using the old RunOnce registry key (because the service doesn't yet exist, or we could
	# use 'Set-Service')
	$hostname = hostname
	$RunOnceCommand = "sc \\$hostname config NetTcpPortSharing start= auto"
	if (Get-ItemProperty -Name "NetTCPPortSharing" -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce' -ErrorAction SilentlyContinue) { 
	    	Write-host "Registry key HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce\NetTCPPortSharing already exists." -ForegroundColor yellow
        	Set-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "NetTCPPortSharing" -Value $RunOnceCommand | Out-Null
	} else { 
	    	New-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "NetTCPPortSharing" -Value $RunOnceCommand -PropertyType "String" | Out-Null
	} 
}

Import-Module ServerManager
$opt = "None"
# Do { 
	clear
	if ($opt -ne "None") {write-host "Last command: "$opt -foregroundcolor Yellow}
	write-host
	write-host Exchange Server 2010 - Prerequisites script
	write-host Please, select which role you are going to install..
	write-host
	write-host '1) Hub Transport'
	write-host '2) Client Access Server'
	write-host '3) Mailbox'
	write-host '4) Unified Messaging'
	write-host '5) Edge Transport'
	write-host '6) Typical (CAS/HUB/Mailbox)'
	write-host '7) Client Access and Hub Transport'
	write-host
	write-host '9) Configure NetTCP Port Sharing service'
	write-host '   Required for the Client Access Server role' -foregroundcolor yellow
	write-host '   Automatically set for options 2,6, and 7' -foregroundcolor yellow
	write-host '10) Install 2007 Office System Converter: Microsoft Filter Pack'
	write-host '    Required if installing Hub Transport or Mailbox Server roles' -foregroundcolor yellow
	write-host '    Automatically set for options 1, 3, 6, and 7' -foregroundcolor yellow
	write-host 
	write-host '13) Restart the Server'
	write-host '14) End'
	write-host
	$opt = Read-Host "Select an option.. [1-14]? "

	switch ($opt)    {
		1 { InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server -restart }
		2 { SetRunOnce; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -restart }
		3 { InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server -restart }
		4 { Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Desktop-Experience -restart }
		5 { Add-WindowsFeature NET-Framework,RSAT-ADDS,ADLDS -restart }
		6 { SetRunOnce; InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -restart }
		7 { SetRunOnce; InstallFilterPack; Add-WindowsFeature NET-Framework,RSAT-ADDS,Web-Server,Web-Basic-Auth,Web-Windows-Auth,Web-Metabase,Web-Net-Ext,Web-Lgcy-Mgmt-Console,WAS-Process-Model,RSAT-Web-Server,Web-ISAPI-Ext,Web-Digest-Auth,Web-Dyn-Compression,NET-HTTP-Activation,RPC-Over-HTTP-Proxy -restart }
		9 { Set-Service NetTcpPortSharing -StartupType Automatic }
		10 {
			# future - auto detect Internet access
			write-host 'Can this server access the Internet?'
			$filtpack = read-host 'Please type (Y)es or (N)o...'
			switch ($filtpack)				{
				Y {InstallFilterPack}
				N {Write-warning 'Please download and install Microsoft Filter Pack from here: http://tinyurl.com/36yrlj'}
			}
		}
		13 { Restart-Computer }
		14 {write-host "Exiting..."}
		default {write-host "You haven't selected any of the available options. "}
	}
# }
# while ($opt -ne 14)

Advertisements
 
1 Comment

Posted by on November 23, 2009 in Exchange Server

 

One response to “how to 全自动完成exchange 2010的preinstall准备

  1. November 24, 2009 at 08:10

    随着powershell2.0的发布,脚本的编写难度大大降低了,只要是能想到的基本上都能实现了,只是复杂度的问题而已。特别是微软各产品组的持续投入,各种服务器的管理工作要比以前简化的多,特别是Windows 2008 r2中的adac,将powershell的使用推向了一个新的高度。

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: