Iis-7

如何安全地刪除 IIS7 日誌

  • February 12, 2018

我已經用Google搜尋了這個沒有太多運氣..但我正在尋找一種手動(一次性執行,免費)/開源方式來安全地從 /inetpub/logs/logFiles 清除 iis 日誌

我見過 ppl 指的是 isslogs.com,我不知道它有多可靠,但即便如此,我也不想要任何類型的計劃任務,也不希望為我不會經常使用的東西付費

我只想要一種簡單安全的方法來從 /inetpub/logs/logFiles 中的多個文件夾中刪除所有日誌

將不勝感激有關如何刪除這些內容的建議或演練。

這是一個刪除 90 天以前的 IIS 日誌文件的腳本

MaxDays = 90 
strComputer = InputBox("This script will delete IIS .log files over 90 days old "_ 
   & "from the machine you specify below.") 
wmiQuery = "Select * from Win32_OperatingSystem" 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colItems = objWMIService.ExecQuery(wmiQuery) 
   For Each objItem In colItems 
       sWindowsPath = objItem.WindowsDirectory 
   Next 
Set objW3SVC = GetObject( "IIS://" & strComputer & "/W3SVC") 
   For Each objSite In objW3SVC 
       If objSite.Class = "IIsWebServer" Then 
           strLogDir = UCase(objSite.LogFileDirectory) 
               strLogDir = Replace(strLogDir,"%WINDIR%",sWindowsPath,1,1,1) 
               strLogDir = Replace(strLogDir,"%SYSTEMROOT%",sWindowsPath,1,1,1) 
               strLogDir = Replace(strLogDir,":","$",1,1,1) 
           objLogFolder = "\\" & strComputer & "\" & strLogDir 
           Set oFSO = CreateObject("Scripting.FileSystemObject") 
           Set oFolder = oFSO.GetFolder(objLogFolder) 
           Set colSubFolders = oFolder.Subfolders 
           For Each oSubFolder In colSubFolders 
               If InStr(UCase(oSubFolder),"W3SVC") Then 
                   For Each oFile In oSubFolder.files 
                       If InStr(LCase(oFile.Name),".log") Then 
                            If (Date - oFile.DateCreated > CInt(MaxDays)) Then 
                               oFSO.DeleteFile(oSubFolder & "\" & oFile.Name) 
                           End If 
                       End If 
                   Next 
               End If 
           Next 
       End If 
   Next 
MsgBox("All done.") 

引用自:https://serverfault.com/questions/276631