http://blogs.technet.com/b/momteam/archive/2014/09/19/iis-log-format-requirements-in-system-center-advisor.aspx
#Script to remotely change IIS log rollover frequency.
#Written by Darren Joyce 2/7/15
param($computer, $period)
if (!$computer){
$computer = read-host 'What is the Name of the server to change log rollover frequency?'
}
if (!$period) {
$period = read-host "What frequency to set? 'Monthly', 'Weekly', 'Daily', 'Hourly' (Default='Hourly')"
$period = "Hourly"
write-host -ForegroundColor Yellow "Connecting to $computer and setting rollover frequency to $period"
Invoke-Command -ComputerName $computer -ScriptBlock { import-module WebAdministration
$period = $($args[0])
write-host "Setting log rollovers..."
get-website | select Name -ExpandProperty Name | `
ForEach-Object{
$sitename = $_
[xml]$configfile = get-content "c:\windows\system32\inetsrv\config\applicationHost.config"
$testValue = $configfile.SelectNodes("/configuration/system.applicationHost/sites/site") | where-object {$_.name -eq "$sitename"}
if ($testValue.logFile) {
$currentPeriod = get-WebConfigurationProperty @("/system.applicationHost/sites/site[@name='$sitename']/Logfile") -name period
Set-WebConfigurationProperty @("/system.applicationHost/sites/site[@name='$_']") -name logFile -value @{period="$period"}
Write-host -ForegroundColor Green "$_ is now set to $period (was $currentPeriod)"
$currentPerioddefault = get-WebConfigurationProperty "/system.applicationHost/sites/sitedefaults/Logfile" -name period
Set-WebConfigurationProperty '/system.applicationHost/sites/sitedefaults' -name logFile -value @{period="$period"}
Write-host -ForegroundColor Green "Site Defaults is now set to $period (was $currentPerioddefault)"
write-host -ForegroundColor Yellow "Completed."
} -ArgumentList $period
' CheckIISRollover.vbs
' Script by Darren Joyce July 2015
' This is designed to be run in SCOM to alert on any websites that have log rollover set to anything but Hourly
' For the purposes of checking machines for OMS
'
' Version 1.0
' Last Update July 2015
option explicit
dim xmlDoc, oAPI,oBag
dim strAlertDescription,strPeriod, strSiteName
dim logfileNode, dlogfileNode, dNode,sNode, sitename
' Set up XML for reading
Set
xmlDoc = CreateObject(
"Msxml2.DOMDocument"
)
xmldoc.SetProperty
"SelectionLanguage"
,
"XPath"
xmlDoc.async =
False
xmlDoc.load
"C:\windows\system32\inetsrv\config\applicationHost.config"
If
xmlDoc.parseError = 0
Then
' Set up the propertybag
oAPI = CreateObject(
"MOM.ScriptAPI"
oBag = oAPI.CreatePropertyBag()
' Set up some needed variables
'strAlertDescription = "The following sites are not set to Hourly IIS log rollver:" & VbCrLf ' We will need this for alert generation.
strAlertDescription =
""
strPeriod =
"Hourly"
' What the correct logfile period should be
'Specify the SiteDefault Node and read the logFile Period attribute.
dlogfileNode =
"/configuration/system.applicationHost/sites/siteDefaults/logFile"
set dNode = xmldoc.SelectSingleNode(dlogfileNode)
'wscript.echo "IIS Global Site Period set to :" & dNode.getattribute("period")
' Check the IIS global logfile period and append to the alert
if dNode.getattribute(
"period"
) <> strPeriod then
strAlertDescription = strAlertDescription &
"IIS Global logfile Configuration : "
& dNode.getattribute(
) & VbCrLf
end if
' Now we the rest of the sites on the IIS box.
' Find the list of configured websites
For
Each
SiteName
In
xmlDoc.selectNodes(
"/configuration/system.applicationHost/sites/site/@name"
strSiteName = SiteName.text
' Now loop through them checking the logFile period attribute, and append to the description if not set correctly.
logfileNode =
"/configuration/system.applicationHost/sites/site[@name='"
& strSiteName &
"']/logFile"
set sNode = xmlDoc.SelectSingleNode(logfileNode)
if sNode is nothing then
' Need this check here as if there is nothing configured, then it throws an exception.
strAlertDescription = strAlertDescription & strSiteName &
" : "
) &
" (Inherited from Site Default Setting)"
& VbCrLf
else
' Check for the period set and append to the description
if sNode.getattribute(
& sNode.getattribute(
next
'Put everything into the propertybag to return to SCOM if an error is found
then
Call
oBag.AddValue(
"Status"
"OK"
"The IIS log file rollover is incorrectly set. It needs to be set to "
& strPeriod &
"."
& VbCrLf &
"The following sites are not correct:"
& VbCrLf & strAlertDescription
"bad"
"Description"
,strAlertDescription)
oAPI.
Return
(oBag)