Project Objective:
Reduce time spend installing Exchange 2010 prerequisites for various roles.

Problem to be solved:
Current method of setting prerequisites involves looking up a webpage. http://technet.microsoft.com/en-us/library/bb691354.aspx#WS08R2 This way you can save a few minutes per machine.

#***********************************************************************
# "Install-ExchPrereqs.ps1"
#
# Written by Aaron Wurthmann (aaron <AT> wurthmann <DOT> com)
#
# If you edit please keep my name as an original author and
# keep me apprised of the changes, see email address above.
# This code may not be used for commercial purposes.
# You the executor,runner,user accept all liability.
# This code comes with ABSOLUTELY NO WARRANTY.
# You may redistribute copies of the code under the terms of the GPL v2.
# -----------------------------------------------------------------------
# Prerequisite:
# Written for Exchange 2010 prerequisites for Windows Server 2008 R2
# -----------------------------------------------------------------------
# 2010.10.21 ver 1.0
#
# Summary:
# Installs Exchange 2010 prerequisites for Windows Server 2008 R2 uses
# required roll option to determine which prerequisites to install.
#
# From: http://technet.microsoft.com/en-us/library/bb691354.aspx#WS08R2
#************************************************************************

Param([string]$switch = 'help')

$Computer='.'
$ExpectedOS='Microsoft Windows Server 2008 R2*'

Function Get-Some-Help {
    write-host ''
    write-host 'Installs Exchange 2010 Prerequisites for Windows Server 2008 R2'
    write-host ''
    write-host 'Usage: Install-Exch-Prereqs.ps1 <options>' 
    write-host ''
    write-host 'Options:'
    write-host '    chtmu    Client Access, Hub Transport, Mailbox, and Unified Messaging server roles prerequisites'
    write-host '    cthm    Client Access, Hub Transport, and Mailbox server roles prerequisites'
    write-host '    cht    Client Access, and Hub Transport server roles prerequisites'
    write-host '    htm    Hub Transport, and Mailbox server roles prerequisites'
    write-host '    cm    Client Access, and Mailbox server roles prerequisites'
    write-host '    c    Client Access server role prerequisites'
    write-host '    ht    Hub Transport server role prerequisites'
    write-host '    m    Mailbox server role prerequisites'
    write-host '    u    Unified Messaging server role prerequisites'
    write-host '    et    Edge Transport role prerequisites'
    write-host ''
    exit(1)
}

Function Get-OS-Version {
    $OS=Get-WMIobject Win32_OperatingSystem -Comp $Computer | Select Caption,ServicePackMajorVersion
    If ($OS.Caption -notlike $ExpectedOS) {
        Get-Some-Help
    }
}

Get-OS-Version

Import-Module ServerManager

Switch ($switch) {
    
    #Default Get Some Help
    default {Get-Some-Help}
    
    #Client Access, Hub Transport, Mailbox, and Unified Messaging server roles.
    chtmu {
        Set-Service NetTcpPortSharing -StartupType Automatic
        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,Desktop-Experience -Restart
    }
    
    #Client Access, Hub Transport, and Mailbox server roles.
    cthm {
    Set-Service NetTcpPortSharing -StartupType Automatic
    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
    }

    #Client Access and Hub Transport server roles.
    cht {
    Set-Service NetTcpPortSharing -StartupType Automatic
    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
    }

    #Hub Transport and Mailbox server roles.
    htm {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}

    #Client Access and Mailbox server roles.
    cm {
    Set-Service NetTcpPortSharing -StartupType Automatic
    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
    }

    #Client Access server role only.
    c {
    Set-Service NetTcpPortSharing -StartupType Automatic
    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
    }

    #Hub Transport or the Mailbox server role.
    ht {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}
    m {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}

    #Unified Messaging server role only.
    u {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 }

    #Edge Transport server role only.
    et {Add-WindowsFeature NET-Framework,RSAT-ADDS,ADLDS -Restart}
}
Be Sociable, Share!