-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebSite_Start_Stop.ps1
105 lines (96 loc) · 3.26 KB
/
WebSite_Start_Stop.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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
param(
[string] $webSiteStartStop # Parameter to Stop/Start Web Site
)
try{
$JsonData = (Get-Content ".\config.json" | Out-String)
$JsonObject = ConvertFrom-Json -InputObject $JsonData -ErrorAction Stop
}
catch{
Write-Host "Please check Json file parameters." -ForegroundColor Red
Read-Host "Enter any key to exit"
Write-Host "`tWe Are Exiting..." -ForegroundColor Magenta
Start-Sleep 3
Exit-PSSession
}
$SiteName = $JsonObject.WebSite
$logpath = $JsonObject.BuildLogsPath.Path
$logfile = $logpath+((Get-Date).ToString('yyyyMMdd'))+'_BuildDeploymentLogs.txt'
function LogWrite {
param (
[String]$logString,
[bool] $iserror = $false
)
$time = Get-Date
if($iserror){
$string = '*** ' +$time.ToString() +' == ERROR == '+ $logString
}
else{
$string = '*** ' +$time.ToString() +' == '+ $logString
}
Add-Content $logfile -Value $string
}
if($webSiteStartStop.ToUpper() -eq "STOP"){
Write-Host 'Stoping IIS' -NoNewline
LogWrite 'Stoping IIS'
iisreset.exe /STOP
LogWrite 'Stoped!'
}
elseif ($webSiteStartStop.ToUpper() -eq "START") {
Write-Host 'Starting IIS' -NoNewline
LogWrite 'Starting IIS'
iisreset.exe /START
LogWrite 'Started!'
}
function StartStopWebSite {
param( [string] $site )
if($webSiteStartStop.ToUpper() -eq "STOP")
{
Write-Host "Stoping $site..." -NoNewline
LogWrite "Stoping $site..."
$currentState = Get-Website | Where-Object {$_.State -eq "Started" -and $_.Name -eq $site } | Select-Object State
If($currentState.state -eq "Started")
{
Stop-Website $site
$currentState = Get-Website | Where-Object {$_.State -eq "Started" -and $_.Name -eq $site } | Select-Object State
If(-not $currentState.state -eq "Started")
{
Write-Host "Stoped!" -ForegroundColor Green
LogWrite "Stoped!"
}
else
{
Write-Host "Please check somethig went wrong!" -ForegroundColor Red
LogWrite "Please check somethig went wrong!!" $true
}
}
else
{
Write-Host "Already Stoped!" -ForegroundColor Green
LogWrite "Already Stoped!"
}
}
if($webSiteStartStop.ToUpper() -eq "START")
{
Write-Host "Starting $site..." -NoNewline
$currentState = Get-Website | Where-Object {$_.State -eq "Started" -and $_.Name -eq $site } | Select-Object State
If(-not $currentState.state -eq "Started")
{
Start-Website $site
$currentState = Get-Website | Where-Object {$_.State -eq "Started" -and $_.Name -eq $site } | Select-Object State
If($currentState.state -eq "Started"){
Write-Host "Started!" -ForegroundColor Green
}
else{
Write-Host "Please check somethig went wrong!" -ForegroundColor Red
}
}
else{
Write-Host "Already Started!" -ForegroundColor Green
}
}
}
# # # # Database backup process Start
# # # foreach($WebSiteName in $SiteName){
# # # $site = $WebSiteName.SiteName
# # # #StartStopWebSite $site
# # # }