9394952

导航

WSUS执行清理时出现错误

参考:

https://docs.microsoft.com/en-us/powershell/module/updateservices/Invoke-WsusServerCleanup?view=windowsserver2016-ps

https://social.technet.microsoft.com/Forums/ie/ko-KR/b7ef1bad-c90a-4eb9-86ed-0628bc8243e0/2816529702wsus2610220986296162596825454242113816935823?forum=systemsmanagementserverzhchs

 

 手工执行清理命令:

powershell:

<#
https://docs.microsoft.com/en-us/powershell/module/updateservices/Invoke-WsusServerCleanup?view=windowsserver2016-ps
Invoke-WsusServerCleanup
      [-UpdateServer <IUpdateServer>]
      [-CleanupObsoleteComputers]
      [-CleanupObsoleteUpdates]
      [-CleanupUnneededContentFiles]
      [-CompressUpdates]
      [-DeclineExpiredUpdates]
      [-DeclineSupersededUpdates]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
#>
echo ....删除的过时更新....
Invoke-WsusServerCleanup -CleanupObsoleteUpdates -Verbose
echo ....删除的过时计算机....
Invoke-WsusServerCleanup -CleanupObsoleteComputers -Verbose
echo ....拒绝的过期更新....
Invoke-WsusServerCleanup -DeclineExpiredUpdates -Verbose
echo ....释放的磁盘空间....
Invoke-WsusServerCleanup -CleanupUnneededContentFiles -Verbose
echo ....删除的过时更新....
Invoke-WsusServerCleanup -DeclineSupersededUpdates -Verbose
echo ....拒绝的过期更新....
Invoke-WsusServerCleanup -DeclineExpiredUpdates -Verbose
echo ....done....

 在WINDOWS做个定时任务,每月执行一下自动清理

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo "C:\Users\Administrator\Desktop\clean_wsus.ps1"

 ######### 2022/09/29/

今天遇到一台WSUS,手工清理还是会出现超时现象,参照文章,要用SMSS连接WID内部数据库 \\.\pipe\MICROSOFT##WID\tsql\query 执行脚本

https://www.sqlshack.com/managing-the-windows-internal-database-wid/

http://jeffbuenting.github.io/wsus/sql/powershell/2018/07/05/WSUS_Cleanup_Timeout.html

http://pnijjar.freeshell.org/2016/wsus-stuck/

--************** vexation code with my small changes
USE SUSDB
DECLARE @var1 INT, @curitem INT, @totaltodelete INT
DECLARE @msg nvarchar(200)
CREATE TABLE #results (Col1 INT) INSERT INTO #results(Col1)
EXEC spGetObsoleteUpdatesToCleanup
SET @totaltodelete = (SELECT COUNT(*) FROM #results)
SELECT @curitem=1
DECLARE WC Cursor FOR SELECT Col1 FROM #results
OPEN WC
FETCH NEXT FROM WC INTO @var1 WHILE (@@FETCH_STATUS > -1)
BEGIN SET @msg = cast(@curitem as varchar(5)) + '/' + cast(@totaltodelete as varchar(5)) + ': Deleting ' + CONVERT(varchar(10), @var1) + ' ' + cast(getdate() as varchar(30))
RAISERROR(@msg,0,1) WITH NOWAIT
EXEC spDeleteUpdate @localUpdateID=@var1
SET @curitem = @curitem +1
FETCH NEXT FROM WC INTO @var1
END
CLOSE WC
DEALLOCATE WC
DROP TABLE #results

 

posted on 2022-09-08 15:24  9394952  阅读(389)  评论(0编辑  收藏  举报