This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
/
IISSetup.ps1
81 lines (67 loc) · 2.2 KB
/
IISSetup.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
$iis = Get-Service W3svc -ErrorAction Ignore
if($iis){
if($iis.Status -eq "Running") {
Write-Host "World Wide Web Publishing is running"
}
else {
Write-Host "World Wide Web Publishing is not running"
exit 1
}
}
else {
Write-Host "World Wide Web Publishing not installed"
exit 1
}
Write-Host "Configuring IIS"
$currentDirectory = (Get-Item -Path ".\").FullName
$iisAppName = "passcore"
$iisAppPort = "8080"
$iisAppPoolName = "Passcore Pool PS"
$iisAppPoolDotNetVersion = ""
$iisAppPoolStartMode = "AlwaysRunning"
#the directory where you will be serving the website from
$directoryPath = (Get-Item -Path $args[0]).FullName
try {
Import-Module WebAdministration
#navigate to the app pools root
Set-Location IIS:\AppPools\
#check if the app pool exists
if (!(Test-Path $iisAppPoolName -pathType container))
{
Write-Host "Creating $($iisAppPoolName)"
#create the app pool
$appPool = New-Item $iisAppPoolName
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
$appPool | Set-ItemProperty -Name "startMode" -value $iisAppPoolStartMode
}
#navigate to the sites root
Set-Location IIS:\Sites\
#check if the site exists
if (Test-Path $iisAppName -pathType container)
{
Write-Host "The site $($iisAppName) already exist"
exit 1
}
Write-Host "Creating $($iisAppName) on IIS"
#create the site
$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation="*:$($iisAppPort):"} -physicalPath $directoryPath
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName
$site = Get-Website $iisAppName
Get-IISAppPool $iisAppPoolName
$site
if(!$site) {
Write-Host "No site was created"
exit 1
}
Start-WebAppPool -Name $iisAppPoolName
Start-Website -Name $iisAppName
$request = Invoke-WebRequest -Uri "http://localhost:$($iisAppPort)"
if ($request.StatusCode -ne 200) {
Write-Host "HTTP Error"
exit 1
}
Write-Host "Website request status: $($request.StatusCode)"
}
finally {
Set-Location $currentDirectory
}