Powershell: win32_offlinefilescache - Pin and Synchronise Folders to Local Offline Files Cache (CSC)

Answered Powershell: win32_offlinefilescache - Pin and Synchronise Folders to Local Offline Files Cache (CSC)

  • Wednesday, May 02, 2012 8:45 AM
     
      Has Code

    Hi all,

    I'm in the proces of writing a script which pins folders into the offline files cache (CSC) on Windows 7 x64 machines. It takes an array of strings (the paths to sync), pins them to the cache and then once everything's pinned it performs a full synchronisation of the CSC on the local box.

    Only it doesn't.

    I've scoured the MSDN libraries on "Win32_OfflineFiles*" and everything looks correct, when the script runs it returns a value of 0 (success), the output to the console shows that the pin command is running succesfully on the folder path.  When you look at Sync Center on the local machine the paths specified in the script aren't pinned anywhere and no synchronisation of the cache has taken place.

    If anyone's got any clues or can offer any help I'd be much obliged, this is driving me nuts now!

    Ok, the code (I'll just include the two functions that aren't working rather than everything):

    This function (poorly named I'll admit) performs the pin action on a single path that is passed to it. It is called from a ForEach loop which checks to see that each path exists before calling this function.   I do not want a synchronisation to happen when the folders are pinned, I need to pin the folders first, then synch afterwards.  (Hence the "fill" flag not being specified on the pin command).  For an explanation as to the flags on the pin command see the MSDN article (its clearer than I could explain!): http://msdn.microsoft.com/en-us/library/windows/desktop/bb309186%28v=vs.85%29.aspx

    Function EnableCSC ($syncpath) {
        $localCSC = [wmiclass]"Win32_OfflineFilesCache"
        $localCSC.Pin($syncpath[0],0x00010801,$true)    
        }

    This second function performs a full synchronisation (or should...) of the CSC on the local machine. The $paths variable passed to it contains only paths which both exist and have previously been pinned by the enableCSC function.

    Function SynchCSC ($paths) {
        if (! $paths) {
            # No arguments, quit. 
            }
        Else {       
            $localCSC = [wmiclass]"Win32_OfflineFilesCache"
            $localCSC.Synchronize($paths,0x00000002)
            }
        }
    

    I've tried running these scripts manually in the console and they execute correctly and return 0 (success) without actually doing anything.  Network traffic running through the NIC isn't affected (you'd expect a jump if a synch occurs, especially when my test user has a good few GBs of data to synch up) and nothing changes in Sync Center in Control Panel (you'd expect to see any new pinned folders and the results of the last CSC synchronisation).

    If anyone's got any clue as to why these two functions don't work I'd be much obliged!

    Many thanks!

All Replies