IIS 6.0

VBScript:

Set IIsWebServerObj = GetObject("IIS://localhost/W3SVC")

For Each Object In IIsWebServerObj

    If (Object.Class = "IIsWebServer") Then 

        WScript.Echo "Updating: " & Object.ServerComment
      
        Set IIsWebSiteObj = GetObject("IIS://localhost/W3SVC/" & Object.Name)

        IIsWebSiteObj.Put "LogExtFileDate",             True
        IIsWebSiteObj.Put "LogExtFileTime",             True
        IIsWebSiteObj.Put "LogExtFileClientIp",         True
        IIsWebSiteObj.Put "LogExtFileUserName",         True
        IIsWebSiteObj.Put "LogExtFileSiteName",         True
        IIsWebSiteObj.Put "LogExtFileComputerName",     True
        IIsWebSiteObj.Put "LogExtFileServerIp",         True
        IIsWebSiteObj.Put "LogExtFileMethod",           True
        IIsWebSiteObj.Put "LogExtFileUriStem",          True
        IIsWebSiteObj.Put "LogExtFileUriQuery",         False
        IIsWebSiteObj.Put "LogExtFileHttpStatus",       True
        IIsWebSiteObj.Put "LogExtFileWin32Status",      True
        IIsWebSiteObj.Put "LogExtFileBytesSent",        True
        IIsWebSiteObj.Put "LogExtFileBytesRecv",        True
        IIsWebSiteObj.Put "LogExtFileTimeTaken",        True
        IIsWebSiteObj.Put "LogExtFileServerPort",       True
        IIsWebSiteObj.Put "LogExtFileUserAgent",        True
        IIsWebSiteObj.Put "LogExtFileCookie",           False
        IIsWebSiteObj.Put "LogExtFileReferer",          True
        IIsWebSiteObj.Put "LogExtFileProtocolVersion",  True
        IIsWebSiteObj.Put "LogExtFileHttpSubStatus",    True
        IIsWebSiteObj.Put "LogExtFileHost",             True
        IIsWebSiteObj.SetInfo

    End If
Next

 

 

IIS 7.0 or Later

PowerShell 2.0:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

$mgr = New-Object Microsoft.Web.Administration.ServerManager    

foreach($site in $mgr.Sites)
{   
    $site.ChildElements["logFile"].Attributes["logExtFileFlags"].Value = `
           
"BytesRecv,BytesSent,ClientIP,ComputerName,Cookie,Date,Host,HttpStatus," + `
            "HttpSubStatus,Method,ProtocolVersion,Referer,ServerIP,ServerPort,SiteName," + `
            "Time,TimeTaken,UriQuery,UriStem,UserAgent,UserName,Win32Status"

}
$mgr.CommitChanges()