-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathIIS_SetPropertiesForFasterStartup.ps1
More file actions
79 lines (74 loc) · 2.13 KB
/
Copy pathIIS_SetPropertiesForFasterStartup.ps1
File metadata and controls
79 lines (74 loc) · 2.13 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#Sets IIS properties for faster load times
#Load IIS Module if not loaded already
Function WebAdministration-VerifyModule
{
If ( ! (Get-module WebAdministration ))
{
Try
{
Import-Module WebAdministration
}
Catch
{
Write-Host "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host "Exception Message: $($_.Exception.Message)"
}
}
$message = "The module WebAdministration verified at (" + (Get-Date).ToString('yyyy.MM[MMM].dd HH:mm:ss zzz') + ")."
Write-Host $message
return $true
}
Function SetIISProperties-AppPools
{
Try
{
#Loop through each app pool
dir IIS:\Sites | ForEach-Object { $appPool = $_.applicationPool
#set start mode to always running
Set-ItemProperty IIS:\AppPools\$appPool -name startMode -value "alwaysrunning"
#set idle timeout to 0 seconds
Set-ItemProperty IIS:\AppPools\$appPool -name processModel.idleTimeout -value "0"
write-output "$appPool app pool set to startMode:always running, idle timeout: 0 seconds"
}
}
Catch
{
Write-Host "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host "Exception Message: $($_.Exception.Message)"
}
}
Function SetIISProperties-Sites
{
Try
{
#Loop through each site
dir IIS:\Sites | ForEach-Object { $siteName = $_.Name
#set preLoadEnabled to true
Set-WebConfigurationProperty "`/system.applicationHost`/sites`/site[@name=`"$siteName`"]/application" -Name "preloadEnabled" -Value "true" -PSPath IIS:\
write-output "$siteName site set to preloadEnabled:True"
}
}
Catch
{
Write-Host "Exception Type: $($_.Exception.GetType().FullName)"
Write-Host "Exception Message: $($_.Exception.Message)"
}
}
#Verify module then run functions
Try
{
If (WebAdministration-VerifyModule)
{
SetIISProperties-AppPools
SetIISProperties-Sites
}
Else
{
Write-Error "Module: WebAdministration did not load!"
}
}
Catch
{
Write-Error "Something wrong with Module: WebAdministration"
}
Exit 0