You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New IIS log folder path, i.e. D:\IISLogs. Default is an empty string.
40
+
41
+
.PARAMETERLogFilePeriod
42
+
Log file period (interval), Hourly|Daily|Weekly|Monthly|MaxSize
43
+
MaxSize configuration not yet implemented
44
+
45
+
.PARAMETERLocalTimeRollover
46
+
Boolean parameter indicating, if the local time shall be used for filenames and rollover
47
+
Default $FALSE
48
+
49
+
.EXAMPLE
50
+
Change the IIS log file location to D:\IISLogs
51
+
.\Set-Webserver.ps1 -LogFolderPath D:\IISLogs
52
+
53
+
.EXAMPLE
54
+
Change the IIS log period to an hourly period
55
+
.\Set-Webserver.ps1 -LogFilePeriod Hourly
56
+
57
+
.EXAMPLE
58
+
Use the local time for filenames and log file rollover
59
+
.\Set-Webserver.ps1 -LocalTimeRollover $true
60
+
61
+
#>
62
+
63
+
64
+
Param(
65
+
[parameter(Position=0,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='New IIS log folder path, i.e. D:\IISLogs')]
66
+
[string]$LogFolderPath='',
67
+
[parameter(Position=1,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='Log file period (Hourly|Daily|Weekly|Monthly|MaxSize)')]
68
+
[string]$LogFilePeriod='',
69
+
[parameter(Position=2,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='$true/$false indicating, if the local time shall be used for filenames and rollover')]
Write-Host'An error occured while trying to write IIS settings. Please check permissions of your account and ensure that PowerShell is running from an elevated prompt.'-ForegroundColor Red
129
+
}
130
+
}
131
+
132
+
# Change IIS default log location and other IIS log settings
133
+
functionChangeIisLogPath
134
+
{
135
+
param
136
+
(
137
+
[string]
138
+
$folderPath
139
+
)
140
+
141
+
Write-Verbose"IIS Log Folder Path to configure: $folderPath"
142
+
Write-Host"Configuring IIS default log location to '$folderPath'"
143
+
144
+
if(Test-Path$folderPath)
145
+
{
146
+
ChangeIisLogSetting $lfpDirectory$folderPath
147
+
}
148
+
else
149
+
{
150
+
Write-Host"New IIS log folder $folderPath does not exist. IIS log file folder configuration has not been changed"-ForegroundColor Red
151
+
}
152
+
}
153
+
154
+
# Change IIS log period
155
+
functionChangeIisLogPeriod
156
+
{
157
+
param
158
+
(
159
+
[string]
160
+
$logPeriod
161
+
)
162
+
163
+
if($AllowedLogFilePeriod-contains$logPeriod)
164
+
{
165
+
Write-Verbose"Changing IIS log periog to: $logPeriod"
166
+
167
+
ChangeIisLogSetting $lfpPeriod$logPeriod
168
+
}
169
+
}
170
+
171
+
# Change IIS LocalTimeRollover setting
172
+
functionChangeLocalTimeRollover
173
+
{
174
+
param
175
+
(
176
+
[bool]
177
+
$logLocalTimeRollover
178
+
)
179
+
180
+
Write-Verbose"Changing IIS log local time rollover to: $logLocalTimeRollover"
$MajorOSVersion= [string](Get-WmiObject Win32_OperatingSystem |Select-Object Version |Select-Object@{n='Major';e={($_.Version.Split('.')[0]+'.'+$_.Version.Split('.')[1])}}).Major
220
+
$AllowedLogFilePeriod=@('Hourly','Daily','Weekly','Monthly') # MaxSize not yet implemented
221
+
222
+
if( CheckWindowsFeature($MajorOSVersion) )
223
+
{
224
+
225
+
Write-Verbose'Configuring IIS log file settings'
226
+
227
+
if($LogFolderPath-ne'')
228
+
{
229
+
# Create IIS Log File Folder, independent from server role
230
+
Create-Folder $LogFolderPath
231
+
232
+
#Change log file settings
233
+
ChangeIisLogPath $LogFolderPath$LogFilePeriod
234
+
}
235
+
236
+
if($LogFilePeriod-ne'')
237
+
{
238
+
ChangeIisLogPeriod $LogFilePeriod
239
+
}
240
+
241
+
if($LocalTimeRollover-ne$null)
242
+
{
243
+
ChangeLocalTimeRollover $LocalTimeRollover
244
+
}
245
+
}
246
+
else
247
+
{
248
+
Write-Host'IIS is currently not installed. Either add the windows feature manually or install Exchange first and adjust the IIS log file location afterwards.'-ForegroundColor Red
0 commit comments