Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Run Invoke-WsusServerCleanup via PowerShell


The Invoke-WsusServerCleanup cmdlet is an essential tool for administrators managing Windows Server Update Services (WSUS). WSUS is a Microsoft tool that enables administrators to manage the distribution of updates released through Microsoft Update to computers in a corporate environment. Over time, WSUS servers can accumulate a lot of unnecessary data, such as obsolete updates, expired updates, and unneeded update files. This can lead to performance degradation and increased storage requirements. The Invoke-WsusServerCleanup cmdlet helps to clean up this data, thereby improving the performance and efficiency of the WSUS server.


This article will guide you through the process of using the Invoke-WsusServerCleanup cmdlet in PowerShell to maintain your WSUS server. We will provide practical examples and sample scripts to illustrate how you can use this cmdlet effectively.


Examples:


1. Basic Cleanup Command:
To perform a basic cleanup of your WSUS server, open PowerShell with administrative privileges and run the following command:


   Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles -CompressUpdates -DeclineExpiredUpdates -DeclineSupersededUpdates

This command will clean up obsolete computers, obsolete updates, unneeded content files, compress updates, and decline expired and superseded updates.


2. Selective Cleanup:
If you want to perform a more selective cleanup, you can specify only the options you need. For example, to clean up only obsolete updates and unneeded content files, use:


   Invoke-WsusServerCleanup -CleanupObsoleteUpdates -CleanupUnneededContentFiles

3. Automating Cleanup with a Scheduled Task:
To ensure your WSUS server remains clean, you can automate the cleanup process by creating a scheduled task that runs the Invoke-WsusServerCleanup cmdlet periodically. Here’s how you can do it:



  • Open Task Scheduler and create a new task.

  • Name the task (e.g., "WSUS Cleanup").

  • Set the trigger to run daily, weekly, or at your preferred interval.

  • In the "Actions" tab, create a new action with the following settings:

    • Action: Start a program

    • Program/script: powershell.exe

    • Add arguments: -Command "Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles -CompressUpdates -DeclineExpiredUpdates -DeclineSupersededUpdates"



  • Save the task.


    This will ensure that your WSUS server is cleaned up regularly without manual intervention.




4. Checking Cleanup Results:
After running the cleanup, you might want to check the results to ensure that the cleanup was successful. You can do this by reviewing the WSUS logs or by using PowerShell to query the WSUS server for the status of updates and computers.


   Get-WsusServer | Get-WsusUpdate -Status Any | Where-Object { $_.IsDeclined -eq $false }

This command will list all updates that are not declined, giving you an overview of the current state of updates on your WSUS server.


To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.