-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremoteDeleteIISite.ps1
More file actions
65 lines (41 loc) · 2.39 KB
/
remoteDeleteIISite.ps1
File metadata and controls
65 lines (41 loc) · 2.39 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# TO DELETE REDIRECTS IN THE NEW PLATFORM
# READS ALIAS FROM A CSV (ONE ALIAS PER LINE)
# TAKES A BACKUP AND DELETES THE SITE AND ITS FOLDER
$servers = "","","";
Write-Host ""
Write-Host "-----------------------------------------SCRIPT BEGIN---------------------------------------------------------------"
Write-Host ""
Write-Host "Reading alias list from C:\aliasToRemove.csv ... ... ..." -ForegroundColor Green
Write-Host ""
try{ #try to import
Import-CSV C:\\aliasToRemove.csv -Header alias | Foreach-Object{
$alias = $_.alias
$site = "redirect_"+$alias
if ([string]::IsNullOrEmpty($alias)){
Write-Host ""
Write-Host "no alias was found on C:\aliasToRemove.csv please verify! (one alias per line expected)" -ForegroundColor Red
Exit
}#closes if
Foreach ($server in $servers){
&{
Write-Host "------------------------------------------------------------------------------------"
Write-Host "Trying to delete redirect:" $site -ForegroundColor Green " on " -NoNewLine
Write-Host $server -ForegroundColor Blue
Invoke-Command -ComputerName $server -ArgumentList $site -ScriptBlock {
param($site)
Remove-WebSite -Name $site -ErrorVariable $errorwebsite
Remove-Item -Recurse D:\Data\sites\$site -ErrorVariable $errorfolder
if(([string]::IsNullOrEmpty($errorwebsite) -or [string]::IsNullOrEmpty($errorfolder))){
Write-Host "::write::" $errorwebsite $errorfolder}
} #ScriptBlock
}#&
}#Foreach Server
}#Foreachobject CSV
}catch{#If the file does not exist.
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host "Does file exist? " $ErrorMessage -ForegroundColor Red
}#Ends catch
Write-Host ""
Write-Host "-----------------------------------------SCRIPT END--------------------------------------------------------------------"
Write-Host ""