Server 2012 R2 and SharePoint 2013: The tool was unable to install Application Server Role, Web Server (IIS) Role.

Seriously...WTF. I spent two days trying to figure out this issue and finally I went digging into %WINDIR% to find my answer.

I was trying to run the Prerequisite Installer for SharePoint 2013 on Server 2012 R2 but I kept getting the error in the title line

The tool was unable to install Application Server Role, Web Server (IIS) Role.

After beating my head against the wall for about 2 days straight, I finally read the log file and the answer was staring at me the entire time.

The installer is trying to run the executable C:\Windows\System32\ServerManagerCMD.exe

`2014-09-03 23:45:23 - "C:\Windows\system32\ServerManagerCmd.exe" -inputpath "somepath"

Taking a look in the system32 directory, you'll see that in R2, ServerManagerCMD.exe doesn't exist! How do we fix that? We do the logical thing. Take ServerManager.exe, copy it, and rename it to ServerManagerCMD.exe. Who cares if it's messy, it works. Case in point:

EDIT

So apparently there is more involved. The prereq installer kept going. I eventually stopped it at 17 hours. I figured it wasn't doing anything (and it wasn't). So I was thinking, well shucks this sucks. But then I had an idea.

On this knowledge base article, Microsoft lists out the requirements for SP2013 roles and features and gives a PowerShell script for it. I tried the script to install the features and then I reran the prereq installer and everything started working.

I simplified this entire process for myself in the future and for everyone who reads this (hopefully people read this).

Import-Module ServerManager

Copy-Item -Path "$($ENV:SystemRoot)\System32\ServerManager.exe" `
    -Destination "$($ENV:SystemRoot)\System32\ServerManagerCmd.exe" -Force

Add-WindowsFeature NET-WCF-HTTP-Activation45,NET-WCF-TCP-Activation45,NET-WCF-Pipe-Activation45

Add-WindowsFeature Net-Framework-Features,Web-Server,Web-WebServer, `
    Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing, `
    Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext, `
    Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor, `
    Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering, `
    Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression, `
    Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server, `
    AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation, `
    AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model, `
    WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation, `
    Server-Media-Foundation,Xps-Viewer

Restart-Computer

Once it reboots, run the prereq installer again.