Solved

Offline Files Sync

Posted on 2011-09-22
3
946 Views
Last Modified: 2012-08-13
Urgent help needed.

All, I currently have a GPO to redirect the My Docs folder to the user home share and make it available offline. (win 2008 AD)
I have set the policy to sync on log off/on, but is there a configuration parameter that will let me sync when idle or every so minutes?  
I know you can do this via sync center on individual machines, but I need to configure it on the GPO level,if possible.
This quite urgent so that I can at least prove is/ s not possible.
thanks,
0
Comment
Question by:cheto06
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Lester_Clayton earned 500 total points
ID: 36582775
I found the attached bit of code by chance a few years ago.

Assuming the user's home share is \\server1\users\%username% then run the script as follows:

wscript.exe PinSync.vbs /ItemPath:\\server1\users\%username% /SyncNow:1 /RecurseSubDirs:1 /Conflicts:latest

It should pin the folder (i.e. make it available offline) and/or sync it immediately.

Create this as a scheduled task, or deploy it as a scheduled task via GPO's  More information about creating a scheduled task via GPO here: http://technet.microsoft.com/en-us/library/cc725745.aspx

Please test before deploying :)
'================
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' Usage: PinSync.vbs /ItemPath:<path> [/Direction:in|out|inout] [/PinNewFiles:1|0] [/SyncNow:1|0] [/RecurseSubDirs:1|0] [/Conflicts:local|remote|latest] [/Machine:value] [/User:value] [/Password:value]

' Demonstrates how to "pin" a UNC path to be ready for caching in the Offline Files cache.
' This should set the Make Available Offline flag

Const cComputerName = "LocalHost"
Const cWMINamespace = "root\cimv2"

' Process commandline arguments

strItemPath = WScript.Arguments.Named("ItemPath")
if Len(strItemPath) = 0 Then
    Wscript.Echo "ItemPath parameter required"
    Err.Raise 449  ' "argument not optional" error
End if

strComputerName = WScript.Arguments.Named("Machine")
If Len(strComputerName) = 0 Then strComputerName = cComputerName

strUserID = WScript.Arguments.Named("User")
If Len(strUserID) = 0 Then strUserID = ""

strPassword = WScript.Arguments.Named("Password")
If Len(strPassword) = 0 Then strPassword = ""

'
' Sync control flags from Win32_OfflineFilesCache.Pin
'
const OfflineFilesPinControlFlagFill            = &H00000001
const OfflineFilesPinControlFlagPinLinkTargets  = &H00000010
const OfflineFilesPinControlFlagForUser         = &H00000020
const OfflineFilesPinControlFlagForUser_Policy  = &H00000040
const OfflineFilesPinControlFlagForAll          = &H00000080
const OfflineFilesPinControlFlagLowPriority     = &H00000200
const OfflineFilesPinControlFlagAsyncProgress   = &H00000400
const OfflineFilesPinControlFlagInteractive     = &H00000800
const OfflineFilesPinControlFlagConsole         = &H00001000
const OfflineFilesPinControlFlagBackground      = &H00010000


const wbemFlagSendStatus = &H00000080

SyncControlFlags = OfflineFilesPinControlFlagFill + _
                   OfflineFilesPinControlFlagForUser_Policy + _
                   OfflineFilesPinControlFlagInteractive + _
                   OfflineFilesPinControlFlagBackground

strSyncNow = WScript.Arguments.Named("SyncNow")
If Len(strSyncNow) <> 0 Then
    if LCase(strSyncNow) = "1" Then 
        SyncControlFlags = SyncControlFlags + fFillSparse
    Elseif LCase(strSyncNow) = "0" Then 
        'SyncControlFlags = SyncControlFlags
    Else
        Wscript.Echo "Invalid SyncNow value [" & strSyncNow & "]"
        Err.Raise 507 ' "an exception occured" error
    End if
End If

strRecurseSubDirs = WScript.Arguments.Named("RecurseSubDirs")
If Len(strRecurseSubDirs) <> 0 Then
    If LCase(strRecurseSubDirs) = "1" Then
        strRecurseSubDirs = True
    Elseif LCase(strRecurseSubDirs) = "0" Then 
        strRecurseSubDirs = False
    Else
        Wscript.Echo "Invalid RecurseSubDirs value [" & strRecurseSubDirs & "]"
        Err.Raise 507 ' "an exception occured" error
    End If
Else
      strRecurseSubDirs = False
End If

strDirection = WScript.Arguments.Named("Direction")
If Len(strDirection) <> 0 Then
    if LCase(strDirection) = "in" Then 
        SyncControlFlags = SyncControlFlags - fSyncOut
    Elseif LCase(strDirection) = "out" Then 
        SyncControlFlags = SyncControlFlags - fSyncIn
    Elseif LCase(strDirection) = "inout" Then
        '
        ' Flags already configured for in/out
        '
    Else
        Wscript.Echo "Invalid direction value [" & strDirection & "]"
        Err.Raise 507 ' "an exception occured" error
    End if
End if

strPinNewFiles = WScript.Arguments.Named("PinNewFiles")
If Len(strPinNewFiles) <> 0 And strPinNewFiles = "0" Then
    SyncControlFlags = SyncControlFlags - fPinNewFiles
End if

strConflicts = WScript.Arguments.Named("Conflicts")
If Len(strConflicts) <> 0 Then
    If LCase(strConflicts) = "local" Then
        SyncControlflags = SyncControlFlags + fCrKeepLocal
    Elseif LCase(strConflicts) = "remote" Then
        SyncControlFlags = SyncControlFlags + fCrKeepRemote
    Elseif LCase(strConflicts) = "latest" Then
        SyncControlFlags = SyncControlFlags + fCrKeepLatest
    End if
End if

Set objWMILocator  = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objWMIServices = objWMILocator.ConnectServer(strComputerName, _
                                                 cWMINameSpace, _
                                                 strUserID, _
                                                 strPassword)
Set objCache       = objWMIServices.Get("Win32_OfflineFilesCache=@")
Set objParams      = objCache.Methods_("Pin").InParameters.SpawnInstance_
Set objSink        = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

'
' Set up the API arguments
'
Dim ItemPaths(0)
ItemPaths(0) = strItemPath

objParams.Paths = ItemPaths
objParams.Flags = SyncControlFlags
objParams.Deep = True

'
' Execute the sync action
'
'objWMIServices.ExecMethodAsync objSink, "Win32_OfflineFilesCache", "Pin", objParams, wbemFlagSendStatus, strRecurseSubDirs
objWMIServices.ExecMethodAsync objSink, "Win32_OfflineFilesCache", "Pin", objParams, wbemFlagSendStatus

'
' Loop until we receive an OnCompleted event
'
bDone = False
While Not bDone
    wscript.sleep 1000
Wend


Sub SINK_OnProgress(UpperBound, Current, Message, objContext)

    DIM PART_REASON, PART_RESULT, PART_RESULTMSG, PART_PATH
    DIM REASON_BEGIN, REASON_END, REASON_ITEMBEGIN, REASON_ITEMRESULT
    DIM Reasons(3)

    '
    ' The message is composed as follows:
    '
    '     <reason>:<result>:<result msg>:<path>
    '
    '     <reason>
    '         Integer indicates reason for progress callback.
    '            Values are:
    '                0 - "Begin" overall operation
    '                1 - "End" overall operation
    '                2 - "Begin Item" operation
    '                3 - "Item result"
    '
    '     <result> 
    '         Integer result code; HRESULT.
    '
    '     <result msg>
    '         Text describing the result.  In most cases this is translated using
    '         the Win32 function FormatMessage.  In some cases a more descriptive
    '         message is provided that is better aligned with Offline Files.
    '
    '     <path>
    '         UNC path string associated with the progress notifcation.  This is
    '         empty for the "Begin" and "End" notifications.
    '

    '
    ' Define indexes of the various parts in the message.
    '
    PART_REASON    = 0
    PART_RESULT    = 1 
    PART_RESULTMSG = 2
    PART_PATH      = 3

    '
    ' The reason codes present in the <reason> part.
    '
    REASON_BEGIN      = 0
    REASON_END        = 1
    REASON_ITEMBEGIN  = 2
    REASON_ITEMRESULT = 3

    '
    ' split the message into the 4 parts and extract those parts.
    '
    Parts = Split(Message, ":", -1, 1)

    Reason    = CInt(Parts(PART_REASON))
    Path      = Parts(PART_PATH)
    Result    = CLng(Parts(PART_RESULT))
    ResultMsg = Parts(PART_RESULTMSG)

    Select Case Reason
        Case REASON_ITEMRESULT
            WScript.Echo Path
            if 0 <> Result then
                Wscript.Echo "  Error: " & Hex(Result) & "  " & ResultMsg
            end if

        Case REASON_END
            if 0 <> Result then
                Wscript.Echo "Error: " & Hex(Result) & "  " & ResultMsg
            end if
    End Select

End Sub

'
' Called when the operation is complete.
'
Sub SINK_OnCompleted(HResult, objLastError, objContext)
    bDone = True
End Sub
'================

Open in new window

0
 

Author Closing Comment

by:cheto06
ID: 36601120
So i guess the answer is "NO" thanks, this is more complicated than necessary.
0
 
LVL 9

Expert Comment

by:Lester_Clayton
ID: 36601200
I re-read your question, and you are right - the answer is no :)  

Offline Files sync occurs at logon, every network change, and at logoff.  A network change can include a wireless network connection link, connecting the ethernet port, or even a VPN connection.  There is no configuration change you can make to enable it to sync outside of these 3 events.

The complex potential solution is yes, very complicated and probably an overkill.

Thank you for the points allocation.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question