0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PowerShellでWSUSのクリーンアップを定期的に自動実行

Posted at

WSUS管理コンソールから任意のタイミングで手動実行できることですが、
Powershellコマンドレットとタスクスケジュールを利用し定期的に掃除してもらうことができます。

WSUS管理コンソールから

image.png

PowerShellから

WSUS_Cleanup.ps1
Powershell -Command "Invoke-WsusServerCleanup 
-CompressUpdates 
-CleanupObsoleteUpdates 
-CleanupObsoleteComputers 
-CleanupUnneededContentFiles 
-DeclineExpiredUpdates 
-DeclineSupersededUpdates" > C:\WSUS_Cleanup.log
WSUS_Cleanup_イベントログへ出力.ps1
$message = "WSUSクリーンアップ処理を開始します。"

Write-EventLog -LogName System -Source "WSUS Cleanup Task" -EventID 65000 -EntryType INFORMATION -Message $message

try{
	$result = (Invoke-WsusServerCleanup -CompressUpdates -CleanupObsoleteUpdates -CleanupObsoleteComputers -CleanupUnneededContentFiles -DeclineExpiredUpdates -DeclineSupersededUpdates)
	if($result -ne $null){
		$message = "WSUSクリーンアップ処理が正常終了しました。`r`n`r`n"+$result
		Write-EventLog -LogName System -Source "WSUS Cleanup Task" -EventID 65001 -EntryType INFORMATION -Message $message
	}else{
		$message = "WSUSクリーンアップ処理が正常終了しましたが結果が空です。"
		Write-EventLog -LogName System -Source "WSUS Cleanup Task" -EventID 65002 -EntryType WARNING -Message $message
	}
}
catch{
	$message = $error[0].Exception.Message
	$message = "WSUSクリーンアップ処理がエラー終了しました。`r`n`r`n"+$message
	Write-EventLog -LogName System -Source "WSUS Cleanup Task" -EventID 65003 -EntryType ERROR -Message $message
}

解説

■不要な更新プログラムおよび更新のリビジョン
-CompressUpdate
-CleanupObsoleteUpdates

■サーバーにアクセスしていないコンピューター
-CleanupObsoleteComputers

■不要な更新ファイル
-CleanupUnneededContentFiles

■期限の切れた更新プログラム
-DeclineExpiredUpdates

■置き換えられた更新
-DeclineSupersededUpdates
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?