/build/static/layout/Breadcrumb_cap_w.png

Script for automatically keeping Windows Update offline scan file up to date

This is a small script for keeping wsusscn2.cab up-to-date. Modify it appropriately for your needs (beware at the paths). One can schedule it as a specific task or add it in the gpedit.msc to run at startup/logon. 
 
C:\en_wumt\wsusscn2cab_downoad.ps1
==========================================================
$datetime = Get-Date -f yyyy-MM-dd-HH-mm
$basename = "wsusscn2_"
$extension = ".cab"

##Remove archived wsusscn2.cab file
function RemoveArchive
{
    if (Test-Path C:\en_wumt\archive\wsusscn2*.cab)
    {
        Remove-Item -Path C:\en_wumt\archive\wsusscn2*.cab
        MoveExisting
    }
    else
    {
        MoveExisting
    }
}

##Move existing wsusscn2.cab file to Archive and rename it with the move date timestamp
function MoveExisting
{
    if (Test-Path C:\en_wumt\wsusscn2.cab)
    {
        Move-Item C:\en_wumt\wsusscn2.cab C:\en_wumt\archive\wsusscn2.cab
        Rename-Item -Path C:\en_wumt\archive\wsusscn2.cab -NewName ($basename+$datetime+$extension)
        DownloadNewCab
    }
    else
    {
        DownloadNewCab
    }
}

##Download the new wsusscn2.cab file
function DownloadNewCab
{
    $client = new-object System.Net.WebClient
    $client.DownloadFile("http://go.microsoft.com/fwlink/?LinkID=74689","C:\en_wumt\wsusscn2.cab")

    ##Validate that the file is there and write entries to the eventlog
if (Test-Path C:\en_wumt\wsusscn2.cab)
    {
        Write-EventLog -Logname "Windows PowerShell" -Source PowerShell -EventId 555 -EntryType Information -Message "wsusscn2.cab file successfully downloaded to C:\en_wumt"
        #Run_wumt
    }
    else
    {
        Write-EventLog -Logname "Windows PowerShell" -Source PowerShell -EventId 8082 -EntryType Error -Message "wsusscn2.cab file download failed"
    Exit
    }
}

##Internet connection testing 
Write-EventLog -Logname "Windows PowerShell" -Source PowerShell -EventId 1000 -EntryType Information -Message "wsusscn2.cab file download script executed"
if (Test-Connection www.google.com -Quiet)
{
    RemoveArchive
}
else
{
    Write-EventLog -Logname "Windows PowerShell" -Source PowerShell -EventId 1234 -EntryType Error -Message "Internet connection DOWN! wsusscn2.cab file download failed"
}
==========================================================

Comments

This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ