June 6, 2014 Update:

The intent of these scripts is to assist those who are required to perform an 'offline' Prerequisite Installation of SharePoint 2013 on Windows Server 2012. It is also for those who wish to learn more about the Prerequisite installation process and/or perform the Prerequisite installation manually. It is intended that you execute each script in order. The reasons for breaking up the scripts into three different scripts are explained in each section below.

There are three scripts within the .zip file download:
  1. Install-SP2013RolesFeatures.ps1
  2. Download-SP2013PreReqFiles.ps1
  3. Install-SP2013PreReqFiles.ps1
Please read this documentation completely prior to using my scripts. There is a lot of insight into the PrerequisiteInstaller.exe process that you should know in these instructions.

NOTE THAT THESE SCRIPTS APPLY ONLY TO WINDOWS SERVER 2012. DO NOT USE THEM ON A WINDOWS SERVER 2008 R2 SP1 SERVER.
 

For complete insight into the potential issues and solutions addressed by these scripts related to installing the SharePoint 2013 Prerequisites on Windows Server 2012 in an offline environment see Install SharePoint 2013 Prerequisites Offline or Manually on Windows Server 2012 - A Comprehensive Guide on the TechNet Wiki

 1. Install-SP2013RolesFeatures.ps1
This script installs all of the nesessary Windows Server 2012 Roles/Features to prepare for a SharePoint 2013 installation. This script was tested and executed on a freshly installed Windows 2012 server after the adding it to my domain and configuring the network adapter with a static IP address. Note that the Roles/Features installed are exactly the same ones Microsoft uses in their Prerequisite install app (in fact, in the same order they execute the Add-WindowsFeatue cmdlet). This scripts supports installing the Roles/Features 'Online' with an Internet connection and 'Offline' without an Internet connection.

Windows Server 2012 Environment Assumptions:
This script assumes (and does not check) that the following Windows Server 2012 Features are installed (they should installed be by default in Windows Server 2012):

Please be sure that the RTM versions (i.e. no CTP versions) are installed in your environment prior to running this script.
Are you installing the Roles/Features 'Online' or 'Offline'?
Why did I write this script?
Procedure:
  1. Download .zip file containing my scripts and extract the .ps1 files to c:\powershellscripts (or another directory of your choosing)
  2. Run PowerShell as Administrator (you can do this from the Start Screen - right click PowrShell and select "Run as Administrator"
  3. Ensure you have set your PowerShell execution policy to Remote-Signed (you can change it later if you need to)
  4. Run this script: 

    PowerShell
    Edit|Remove
    c:\powershellscripts\Install-SP2013RolesFeatures.ps1 
    
    1. When you run the script, it will prompt you to decide if you are installing the Roles/Features 'Online' or 'Offline'. If you select 'Online' your server must have an Internet Connection. In this case, Windows Update will be used to download then install binaries and other files related to the installation of .NET 3.5. If you select 'Offline', the script will prompt you for the location of your Windows Server 2012 installation media. The binaries and other files required are included in this media. Enter the path (without a trailing slash) to the 'sources\sxs' folder (for example D:\sources\sxs) of your Windows Server 2012 installation media. This can be a mounted ISO, a local drive or a UNC path. Using the 'Offline' method will install the Roles/Features faster than the 'Online' method. 
    2. The script will prompt you to Reboot your server after the Roles/Features have installed. You can opt in or out, but I recommend that you opt in and reboot your server as you need to in order for the Windows Features to be configured correctly.


2. Download-SP2013PreReqFiles.ps1
This script downloads the ENGLISH versions of the required Prerequisite files for SharePoint 2013 on Windows Server 2012. It stores them in a directory of your choosing.
Why did I write this script?

Procedure:
  1. Create a local directory where the script can save the SharePoint 2013 Pre-requisite downloads. For example, c:\sp2013downloads.
  2. Run PowerShell as Administrator (you can do this from the Start Screen - right click PowerShell and select "Run as Administrator"
  3. Run this script: 
    PowerShell
    Edit|Remove
    c:\powershellscripts\Download-SP2013PreReqFiles.ps1
     
    You will be required to define a path where the script can save the downloaded files. (e.g. c:\sp2013downloads)
  4. Sit back and let the files download.
 
3. Install-SP2013PreReqFiles.ps1
This script utilizes the PrerequisiteInstaller.exe included in the SharePoint 2013 installation media to install the necessary prerequisites for SharePoint 2013 on Windows Server 2012.

Assumptions:
You have downloaded the SharePoint 2013 installation media from MSDN, TechNet or Volume Licensing/Software Assurance etc.

Notes:
Why did I write this script?
There are two different scenarios for how you can use this script

Procedure - Scenario 1:
  1. Copy the SharePoint 2013 installation media files into a local directory on you Windows Server 2012 server. For example, c:\sp2013.
  2. Copy the Prerequisite files into the c:\sp2013\prerequisiteinstallerfiles directory.
  3. Run PowerShell as Administrator (you can do this from the Start Screen - right click PowerShell and select "Run as Administrator"
  4. Run this script:
    PowerShell
    Edit|Remove
    c:\powershellscripts\Install-SP2013PreReqFiles.ps1
    You will be required to define a path where to your SharePoint 2013 installation media. (e.g. c:\sp2013). Watch the Prerequisite installer tool install all of the prerequisites.

  5. When the installer is complete, reboot your server prior to installing SharePoint 2013. You should now be able to run the SharePoint 2013 installer, bypassing the Pre-requisite step.


Procedure - Scenario 2:
  1. Copy the SharePoint 2013 installation media files into a local directory on you Windows Server 2012 server. For example, c:\sp2013.
  2. Copy the Prerequisite files into the c:\sp2013\prerequisiteinstallerfiles directory.
  3. Run PowerShell as Administrator (you can do this from the Start Screen - right click PowerShell and select "Run as Administrator"
  4. Run this script:

    PowerShell
    Edit|Remove
    c:\powershellscripts\Install-SP2013PreReqFiles.ps1 
    
     
    You will be required to define a path where to your SharePoint 2013 installation media. (e.g. c:\sp2013). On this run, defining the path isn't technically required as it will add the Windows Server 2012 Roles/Features for SharePoint 2013. When the Roles/Features are installed, click Finish and your server will reboot.

  5. After the reboot, when you login, if the PrerequisiteInstaller launches, close the installer.Prerequisite installer tool install all of the prerequisites.
  6. Run this script: 

    PowerShell
    Edit|Remove
    c:\powershellscripts\Install-SP2013PreReqFiles.ps1
     
    You will be required to define a path where to your SharePoint 2013 installation media. (e.g. c:\sp2013). Watch the Prerequisite installer tool install all of the prerequisites.
  7. When the installer is complete, reboot your server prior to installing SharePoint 2013. You should now be able to run the SharePoint 2013 installer, bypassing the Pre-requisite step.
 
If you have any questions or feedback start a Gallery Discussion!

Cheers,

Craig