Pourya.M
Pourya.M

Reputation: 73

Remove multiple website from IIS 7.5

I have a web server for shared webhosting purpose based on windows server 2008 R2 and IIS 7.5. There are currently 450 websites in it IIS server. I want to remove all of the website from the server because this server has been gone out of production. Is there any script in powershel to automate the deletion of 450 websites or I have to remove them one by one manually.

Upvotes: 7

Views: 13589

Answers (5)

Tom Stickel
Tom Stickel

Reputation: 20451

Big Thanks to David Martin, but here is what I needed to do in order for it to install and work.

# Get WebAdminstration module
Add-PSSnapin WebAdministration -ErrorAction SilentlyContinue 
# Import module in order to run it
Import-Module WebAdministration
# Remove All Websites from IIS
Remove-Website -Name *

I hope this helps others.

Works with IIS 8.5 (Windows Server 2012 R2)

Upvotes: 6

Amit Baranes
Amit Baranes

Reputation: 8152

If you would like to remove web sites using appcmd , use the following script :

    $appCmd = "C:\windows\system32\inetsrv\appcmd.exe"

    $sites = & $appcmd list site /text:name | where {$_ -eq "SITENAME"} 

    $sites | %{ & $appCmd delete site $_}

Upvotes: 0

HeedfulCrayon
HeedfulCrayon

Reputation: 857

This should remove all websites and then remove all webapp pools

Import-Module WebAdministration
Get-Website | Remove-Website
Get-ChildItem IIS:\AppPools\ | Select-Object Name | Foreach-Object {Remove-WebAppPool $_}

Upvotes: 2

Tatarao Vana
Tatarao Vana

Reputation: 621

When installed on IIS 7.0 or later Web Deploy adds a context menu item to IIS manager called Deploy.

There are multiple actions available here one of which is the Delete action. There are two options depending on what node you have selected in IIS manager:

Web site :   Deploy >> Delete Web Site and Content
Application: Deploy >> Delete Application and Content

For more details...please check below link

http://blogs.iis.net/richma/archive/2010/07/03/deleting-iis-web-sites-applications-and-their-content-with-web-deploy.aspx

Upvotes: 1

David Martin
David Martin

Reputation: 12248

The Web Server (IIS) Administration Cmdlets in Windows PowerShell will help you here.

The following will remove all websites:

Import-Module WebAdministration
Get-Website | Remove-Website

This won't remove any files so that should be done separately.

Upvotes: 16

Related Questions