Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

IIS 10.0 のログファイルを自動的に削除する

0
Posted at

はじめに

IIS にはデフォルトでログを自動削除する機能が備わっていないため、その備忘録です。

改訂履歴

  • 2026/07/15 : 初版公開。

本文

1. 環境

  • IIS 10.0
  • Windows Server 2025 Datacenter Evaluation 24H2
  • VMware Workstation Pro 25H2u1

2. 方法

以下のコマンドで削除対象(今回の場合は 100 日が経過したログ)の確認や、実際に削除が行えます。

削除対象の確認.bat
forfiles /p "C:\inetpub\logs\LogFiles" /s /m *.log /d -100 /c "cmd /c echo @path"
削除.bat
forfiles /p "C:\inetpub\logs\LogFiles" /s /m *.log /d -100 /c "cmd /c del /q @path"

また以下のコマンドで、削除処理をタスクスケジューラに「毎日深夜 2 時に実行」で登録することもできます。

タスクスケジューラに削除タスクを登録する.bat
schtasks /Create ^
/TN "IIS Log Cleanup" ^
/SC DAILY ^
/ST 02:00 ^
/RU SYSTEM ^
/RL HIGHEST ^
/TR "forfiles.exe /p \"C:\inetpub\logs\LogFiles\" /s /m *.log /d -100 /c \"cmd /c del /q @path\"" ^
/F

おわりに

長期運用を行うなら、削除忘れには気を付けましょう。

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?