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