Powershell: win32_offlinefilescache - Pin and Synchronise Folders to Local Offline Files Cache (CSC)
-
Wednesday, May 02, 2012 8:45 AM
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.aspxFunction 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
-
Wednesday, May 02, 2012 2:35 PMI recall working of CSC folder some years ago, and having permissions issues. Try to add the user you are running your script full permissions on the CSC folder
Cyreli
-
Wednesday, May 02, 2012 4:03 PM
Hi Cyreli,
I should have clarified earlier, I've tried running the script as both standard users and a local admin and it has no affect. The Sync Center GUI behaviour works correctly whether logged on as an admin or as a standard user and I would expect the WMI implementation of the same system to follow suit in terms of permissions.
Thanks!
-
Monday, May 07, 2012 3:12 AMModerator
Hi,
I would like suggest you go through the below similar threads:
WMI Win32_OfflineFilesCache does not pin items
http://social.technet.microsoft.com/Forums/en/ITCG/thread/afbf45fb-2ccf-4ea7-b57e-c133a52773b1
Cannot scripting Windows 7 offline files synchronization with WMI Class "Win32_OfflineFilesCache"
http://social.technet.microsoft.com/Forums/en/ITCG/thread/d64bb655-e51e-4a33-bca1-97a0521eb242
Regards,
Yan Li
Yan Li
TechNet Community Support
- Marked As Answer by Yan Li_Microsoft Contingent Staff, Moderator Wednesday, May 09, 2012 1:29 AM

