-
Notifications
You must be signed in to change notification settings - Fork 0
/
SiteConfiguration.ps1
137 lines (118 loc) · 10 KB
/
SiteConfiguration.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
#Need to Impoert teh WebAdministration
write-host "In localsitePVS2"
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Import-Module Webadministration
#Start:: Set the default parameters
$JsonData = (Get-Content "B:\OFFICEBOX\OBEnvironmentAutomation\Officebox_environment\config.json" | Out-String)
#Start:: Json data to PSObject
function ConvertFrom-Json([string] $JsonData){
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") | out-null
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
write-output (new-object -type PSObject -property $ser.DeserializeObject($JsonData))
}
#End:: Json data to PSObject
#$JsonObject = ConvertFrom-Json -InputObject $JsonData
$JsonObject = ConvertFrom-Json $JsonData
$AppPoolsList = $JsonObject.ApplicationPoolName
$SiteName = $JsonObject.WebSite
$AppFolder = $JsonObject.FolderPath
$progesscount = 1 #Bool Data
$managedRuntimeVersion = "v4.0" #String Data
$ideltimeout = 360 #Date Time Data
$enable32BitAppOnWin64 = 1 #Bool Data
$loadUserProfile = 0 #Bool Data
$connectionTimeout = 3600 #Date Time Data
$Path = ""
#End::
#Create the application pool.
Function CreateAppPool {
Param([string] $appPoolName)
if(Test-Path ("IIS:\AppPools\" + $appPoolName)) {
Write-Host "The App Pool $appPoolName already exists" -ForegroundColor Yellow
}
else{
$appPool = New-WebAppPool -Name $appPoolName
}
}
#set the properties for the application pool.
Function SetProperties {
Param([string] $appPoolName,
[string] $managedRuntimeVersion,
[bool]$enable32BitAppOnWin64)
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] $AppFolder
)
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 $AppFolder -ApplicationPool $WebAppName
}
}
#Create the site by passing Website Name, Application pool name and physical path
Function CreateWebSite{
Param([String] $WebSiteName,
[String] $appPoolName,
[String] $AppFolder)
if(Test-Path ("IIS:\Sites\$WebSiteName")){
Write-Host "Web Site $WebSiteName Already Exists" -ForegroundColor Yellow
}
else{
New-WebSite -Name $WebSiteName -Port 80 -HostHeader $WebSiteName -ApplicationPool $appPoolName -PhysicalPath $AppFolder
Write-Host "Web Site $WebSiteName Created successfully" -ForegroundColor Green
}
}
#Set Properties for the Website
Function SetWebSiteProperties{
Param([String] $WebSiteName)
Set-ItemProperty IIS:\Sites\$WebSiteName -Name limits.connectionTimeout -Value ([TimeSpan]::FromSeconds($connectionTimeout))
}
#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 $AppFolder
foreach($WebSiteName in $SiteName){
$statusname = $WebSiteName.SiteName
Write-Progress -Activity "Creating Website " -Status "$statusname" `
-percentComplete ($progesscount / $SiteName.Count*100)
#$path = $($AppFolder.Path+$WebSiteName.SiteName) #PS version 3
$path = $($AppFolder[0].Path+''+$WebSiteName.SiteName)
CreateWebSite $WebSiteName.SiteName $WebSiteName.SiteName $path
#Log ==> Set the Properties for the Web Site
SetWebSiteProperties $WebSiteName.SiteName
$progesscount++
}
#Script for updating the host file
foreach($WebSiteName in $SiteName){
$hostName = $WebSiteName.SiteName
If ((Get-Content "$($env:windir)\system32\Drivers\etc\hosts" ) -notcontains "127.0.0.1 $hostName")
{
ac -Encoding UTF8 "$($env:windir)\system32\Drivers\etc\hosts" "127.0.0.1 $hostName"
}
}
#Once sites has been created, Browse the main site
$ListSiteName = $SiteName
$browseSiteName = $ListSiteName[0].SiteName
start http://$browseSiteName