-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalSiteCOnfiguration.ps1
182 lines (153 loc) · 6.4 KB
/
LocalSiteCOnfiguration.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#Need to Impoert teh WebAdministration
write-host "In LocalSiteConfiguration"
Import-Module Webadministration
#Start:: Set the default parameters
$jsonData = (Get-Content "config.json" -Raw)
$JsonObject = Microsoft.PowerShell.Utility\ConvertFrom-Json -InputObject $JsonData
$AppPoolsList = $JsonObject.ApplicationPoolName
$SiteName = $JsonObject.WebSite
$WebSitePath = $JsonObject.WebSiteDestinationpath.path
$progesscount = 1
$managedRuntimeVersion = "v4.0"
$ideltimeout = 360
$enable32BitAppOnWin64 = 1
$loadUserProfile = 0
$connectionTimeout = 3600
#End::
$cd = $JsonObject.currentDirectory.path
$logfile = $cd+"\Installationlog.log"
function LogWrite {
param ([String]$logString)
$time = Get-Date
$string = '*** ' +$time.ToString() +' == '+ $logString
Add-Content $logfile -Value $string
}
LogWrite "In LocalSiteConfiguration"
#Create the application pool.
Function CreateAppPool {
Param([string] $appPoolName)
LogWrite "Creating Application pool"
if(Test-Path ("IIS:\AppPools\" + $appPoolName)) {
Write-Host "The App Pool $appPoolName already exists" -ForegroundColor Yellow
LogWrite "The App Pool $appPoolName already exists"
}
else{
$appPool = New-WebAppPool -Name $appPoolName
}
}
#set the properties for the application pool.+
Function SetProperties {
Param([string] $appPoolName,
[string] $managedRuntimeVersion,
[bool]$enable32BitAppOnWin64)
LogWrite "Set the Properties Application pool"
Set-ItemProperty IIS:\AppPools\$appPoolName managedRuntimeVersion $managedRuntimeVersion
Set-ItemProperty IIS:\AppPools\$appPoolName processModel.idleTimeout -value ( [TimeSpan]::FromMinutes($ideltimeout))
#Set-ItemProperty IIS:\AppPools\$appPoolName processModel.loadUserProfile $loadUserProfile
if ($enable32BitAppOnWin64)
{
Set-ItemProperty IIS:\AppPools\$appPoolName enable32BitAppOnWin64 $enable32BitAppOnWin64
}
}
Function CreateWebApp {
Param([string] $WebSiteName,
[string] $WebAppName,
[string] $WebSitePath
)
LogWrite "Create Web Application"
if (Test-Path ("IIS:\Sites\$WebSiteName\$WebAppName")){
Write-Host "Web App $WebAppName already exists" -ForegroundColor Yellow
return
}
else {
New-WebApplication -Site $WebSiteName -name $WebAppName -PhysicalPath $WebSitePath -ApplicationPool $WebAppName
}
}
#Create the site by passing Website Name, Application pool name and physical path
Function CreateWebSite{
Param([String] $WebSiteName,
[String] $appPoolName,
[String] $WebSitePath)
LogWrite "Creating Web Site $WebSiteName"
if(Test-Path ("IIS:\Sites\$WebSiteName")){
Write-Host "Web Site $WebSiteName Already Exists" -ForegroundColor Yellow
LogWrite "Web Site $WebSiteName Already Exists"
}
else{
New-WebSite -Name $WebSiteName -Port 80 -HostHeader $WebSiteName -ApplicationPool $appPoolName -PhysicalPath $WebSitePath
Write-Host "Web Site $WebSiteName Created successfully" -ForegroundColor Green
LogWrite "Web Site $WebSiteName Created successfully"
}
}
#Set Properties for the Website
Function SetWebSiteProperties{
Param([String] $WebSiteName)
LogWrite "Set the web site properties for $WebSiteName"
Set-ItemProperty IIS:\Sites\$WebSiteName -Name limits.connectionTimeout -Value ([TimeSpan]::FromSeconds($connectionTimeout))
}
#START::Create task Website
Function CreateTaskSite{
$tasksiteName = "task.officebox.local"
$taskSitePath = $($WebSitePath+$tasksiteName)
LogWrite "Creating task site and Application Pool."
CreateAppPool $tasksiteName
SetProperties $tasksiteName $managedRuntimeVersion $enable32BitAppOnWin64
LogWrite "Creating Task site"
if(Test-Path ("IIS:\Sites\$tasksiteName")){
Write-Host "Web Site $tasksiteName Already Exists" -ForegroundColor Yellow
LogWrite "Web Site $tasksiteName Already Exists"
}
else{
New-WebSite -Name $tasksiteName -Port 8787 -HostHeader 'localhost' -ApplicationPool $appPoolName -PhysicalPath $taskSitePath
if(Test-Path ("IIS:\Sites\$tasksiteName")){
Write-Host "Web Site $tasksiteName Created successfully" -ForegroundColor Green
LogWrite "Web Site $tasksiteName Created successfully"
SetWebSiteProperties $tasksiteName
}
}
}
#END::
#Log ==> Creating Application Pool
foreach($appPoolName in $AppPoolsList){
#Start:: code for progress status
$appPool = $appPoolName.AppPool
#Write-Progress -Activity "Creating Application Pool" -Status "$appPool" `
#-percentComplete ($progesscount / $AppPoolsList.Count*100)
#End::
CreateAppPool $appPoolName.AppPool
#Log ==> Set the Properties for the Application pool
SetProperties $appPoolName.AppPool $managedRuntimeVersion $enable32BitAppOnWin64
$progesscount++
}
#Log ==> Application Pool created successfully!
$progesscount = 1
#CreateWebApp $WebSiteName $WebAppName $WebSitePath
foreach($WebSiteName in $SiteName){
$statusname = $WebSiteName.SiteName
#Write-Progress -Activity "Creating Website " -Status "$statusname" `
#-percentComplete ($progesscount / $SiteName.Count*100)
$path = $($WebSitePath+$WebSiteName.SiteName)
CreateWebSite $WebSiteName.SiteName $WebSiteName.SiteName $path
#Log ==> Set the Properties for the Web Site
SetWebSiteProperties $WebSiteName.SiteName
$progesscount++
}
#Invoke CreateTaskSite for creating task site
CreateTaskSite
#Script for updating the host file
LogWrite "Adding the host entries!"
foreach($WebSiteName in $SiteName){
$hostName = $WebSiteName.SiteName
LogWrite "$hostName Added to Host file."
If ((Get-Content "$($env:windir)\system32\Drivers\etc\hosts" ) -notcontains "127.0.0.1 $hostName")
{
Add-content -Encoding UTF8 "$($env:windir)\system32\Drivers\etc\hosts" "127.0.0.1 $hostName"
}
}
#Once sites has been created, Browse the main site
$ListSiteName = $SiteName.SiteName
$browseSiteName = $ListSiteName[0]
Start-Process "http://$browseSiteName"
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -I
read-host "check the browser!"
LogWrite "check the browser!"