Question:
How do you remove SharePoint 2013 from a server using PowerShell?
Answer:
Rarely do we find people who want to uninstall SharePoint 2013 from a server. More often than not they will simply kill the server and rebuild, but that is hitting it with a Mac Truck when sometimes a sledge hammer is all we need. Lets use our trusty PowerShell sledgehammer instead.
Steps:
1) Before we even start, go into Central Admin and ensure no services are running on the server. This saves us from load balancing issues and ensures that single server services are on another server.
2) Uninstall SharePoint on the server.
$SP = GWMI Win32_Product | ?{$_.name -match “Microsoft SharePoint Server 2013}
$SP.UnInstall()
3) Add in the server manager module
Import-Module ServerManager
4) Now SharePoint is gone lets continue cleaning up what we installed.
Remove-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 -Source D:\Sources\sxs
5) Now lets remove .Net 4.5 features
Remove-WindowsFeature NET-WCF-HTTP-Activation45,NET-WCF-TCP-Activation45,NET-WCF-Pipe-Activation45-Source D:\Sources\sxs
*NOTE – Instead of Add or Remove you can call Uninstall-windowsfeature or Install-windowsfeature. Add and Remove are aliases for Install and Uninstall.
SharePoint is now removed along with all pre-requisites off of a server.