Removing Default Web Site & Application Pool

I’m always sick and tired of having to remove the IIS Default Web Site and DefaultAppPool after I’ve installed the Web Roles in Windows Server 2012 R2.  So, I created a short script that will remove them.

# Check for Admin Access (UAC)
$User = [Security.Principal.WindowsIdentity]::GetCurrent()
$Role = ( New-Object Security.Principal.WindowsPrincipal $user ).IsInRole( [Security.Principal.WindowsBuiltinRole]::Administrator )
if ( -not $Role )
{
    Write-Warning "To perform some operations you must run an elevated Windows PowerShell console."
}
else
{
    Get-WebSite -Name "Default Web Site" | Remove-WebSite -Confirm:$false -Verbose
    Remove-WebAppPool -Name "DefaultAppPool" -Confirm:$false -Verbose
}

DISCLAIMER: These materials are provided “AS IS” without any express or implied warranty of any kind.

2 thoughts on “Removing Default Web Site & Application Pool”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.