-
Notifications
You must be signed in to change notification settings - Fork 61
/
IIS-delete-website.ps1
33 lines (30 loc) · 1.18 KB
/
IIS-delete-website.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This script will go and delete the IIS website that you specify, along with the corresponding app pool and DNS entry.
# It is meant to be run from your local computer, so you don't have to log in to your web server and domain controller to delete the website, all you have to do is run the script.
param(
[Parameter(Mandatory=$true)]$webserver,
[Parameter(Mandatory=$true)]$dnsserver
)
$sites = Invoke-Command -ComputerName $webserver -ScriptBlock {
$websites = Get-Website
return $websites
}
Write-Host $sites
$todelete = Read-Host "Please type the name of the website you would like to delete (see list above)"
foreach ($site in $sites) {
if ($todelete -eq $sites.Name) {
Delete-Website($todelete)
}
}
function Delete-Website($name, $webserver, $dnsserver) {
$url = Invoke-Command -ComputerName $webserver -ArgumentList $todelete -ScriptBlock {
param($name)
$url = (Get-Website -Name $name).Bindings.Collection[0].BindingInformation.Split(":")[1]
$apppool = (Get-Website -Name $name).applicationPool
Remove-Website -Name $name
Remove-WebAppPool -Name $apppool
return $url
}
if (($url -ne "") -and ($url -ne $null)) {
Remove-DnsServerZone -ComputerName $dnsserver -Name $url
}
}