Monday, January 12, 2015

WSUS for SCCM won't sync

Sometimes the most basic fix can get you over a hurdle so you can spend time fixing it instead of fighting a contanst fire:


Manual Sync of WSUS from the "Update Repository" node works but the automated sync fails like such

Sync failed: The operation has timed out. Source: Microsoft.UpdateServices.Internal.ApiRemoting.ExecuteSPSearchUpdates
Sync failed. Will retry in 60 minutes

Quick Resolution:
You could manually sync the server on the schedule but that doesn't solve the problem

But why doesn't it work for the automated approach?  You may see in the console that it starts to download but never finisheds.  This could be a problem withe the SQL ram or the Server ram available.  Does it sync for the first few times after your restart your machine.  It could be the load on your site server has changed recently.

I pulled part of the script from Microsft Technet and others from my internal script base.  I then used the server Scheduled Task to kick this off for me until I could find a solid solution.

Another way would be to somehow force a script to run the manual sync for you:

Change the following names:
SITE_SERVER_NAME -> servername

Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy
Set swbemServices= swbemLocator.ConnectServer("SITE_SERVER_NAME", "root\sms\site_SITE_CODE")

Set context = CreateObject("WbemScripting.SWbemNamedValueSet")
'context.Add "LocaleID", "MS\1033"
'context.Add "MachineName", "SITE_SERVER_NAME "
Context.Add "SessionHandle", swbemServices.ExecMethod("SMS_SiteControlFile", "GetSessionHandle").SessionHandle

SynchronizeSoftwareUpdatePoint swbemServices,context,"SITE_CODE"

Sub SynchronizeSoftwareUpdatePoint(swbemServices,swbemContext,siteCode)
    ' Load site control file and get the SMS_WSUS_SYNC_MANAGER component section.
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
    ' Calculate the current timestamp (number of seconds from 1/1/1970 to current time UTC).
    calculatedUTCOffsetinSeconds = (8 * 60 * 60)
    currentTimestamp = datediff("s", "1/1/1970 12:00:00 AM", now()) + calculatedUTCOffsetinSeconds
    Query = "SELECT * FROM SMS_SCI_Component " & _
            "WHERE ComponentName = 'SMS_WSUS_SYNC_MANAGER' " & _
            "AND SiteCode = '" & siteCode & "'"
    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet
        ' Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props        
            ' Setting: Sync Now
            If vProperty.PropertyName = "Sync Now" Then
                ' Modify the value.
                vProperty.Value = currentTimestamp
            End If
             ' Update the component in your copy of the site control file. Get the path
             ' to the updated object, which could be used later to retrieve the instance.
             Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
    ' Commit the change to the actual site control file.
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext
    ' Release copy of the site control file.
    swbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle swbemContext.Item("SessionHandle").Value
End Sub
Why did I subtract time?

The time is instant but I found sometimes there was a lag before it could read, so by subtracting time it makes it a future event.