test2

USE SUSDB;
GO

EXEC sp_updatestats;
GO

DECLARE @TableName NVARCHAR(255)

DECLARE TableCursor CURSOR FOR
SELECT name FROM sys.tables

OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName

WHILE @@FETCH_STATUS = 0
BEGIN
    PRINT 'Rebuilding indexes on ' + @TableName
    EXEC('ALTER INDEX ALL ON [' + @TableName + '] REBUILD')
    FETCH NEXT FROM TableCursor INTO @TableName
END

CLOSE TableCursor
DEALLOCATE TableCursor
GO
``

param(
    [string]$UpdateServer = "localhost",
    [int]$Port = 8530,
    [bool]$UseSSL = $false
)

Write-Output "=== WSUS Superseded Updates Decline Start ==="

# WSUSモジュール読み込み
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null

# WSUSサーバ接続
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($UpdateServer, $UseSSL, $Port)

# すべての更新を取得
$updates = $wsus.GetUpdates()

$declinedCount = 0

foreach ($update in $updates) {
    if ($update.IsSuperseded -and -not $update.IsDeclined) {
        $update.Decline()
        $declinedCount++
        Write-Output "Declined: $($update.Title)"
    }
}

Write-Output "Total Declined Updates: $declinedCount"
Write-Output "=== Finished ==="
``