Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

Using PowerShell to get IIS 8.5 Log File information

I need to know how to adjust one setting in IIS 8.5 that is under the logging icon. Within that section at the very bottom you have the section called "Log File Rollover." There is an option called "Do not create new log files." I have no idea to access that one option. I use the following code and I can get all the information from that section but that one option.

$test = Get-ItemProperty "IIS:SitesDefault Web Site"
$test.logfile

enter image description here

I have looked at the Microsoft IIS documentation for logging and I can't find anything.

Any help is greatly appreciated.

question from:https://stackoverflow.com/questions/65921984/using-powershell-to-get-iis-8-5-log-file-information

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This particular setting is not clearly shown in the logFile object. It is a combination of settings. Property period should have a value of MaxSize and truncateSize should have the maximum allowable value for that field.

$test = Get-ItemProperty "IIS:SitesDefault Web Site"
# returns True for Do not create new log files option
$test.logFile.truncateSize -eq 4gb-1 -and $test.logFile.period -eq 'MaxSize'

Note that my instance's maximum allowable log size is 4GB. Due to rounding, I could not solely rely on the 4gb output from PowerShell. One byte needed to be subtracted from the value. You can configure the settings for the required scenario using the following:

Set-ItemProperty 'IIS:SitesDefault Web Site' -Name logFile.period -value 'MaxSize'
Set-ItemProperty 'IIS:SitesDefault Web Site' -Name logFile.truncateSize -value $(4gb-1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...