Reputation: 73
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
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
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
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
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
Upvotes: 1
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