0

A recent upgrade to Microsoft 365/OneDrive allows users to add a shortcut to a document library into the root of their personal OneDrive folder:

Add shortcut to OneDrive

It looks like this in File Explorer:

OneDrive shortcuts in File Explorer

How do you identify these folders in PowerShell? Get-ChildItem returns identical fields for this shortcut as for the "Documents" folder, specifically Mode and Attributes fields are identical so can't be used to distinguish.

The problem I've got is that we have a script that backs up the user's OneDrive folder (as OneDrive is horrible when you restore a VM snapshot) but it's now dragging in the entire contents of the target folders. The script uses robocopy and /xj doesn't work. I need to identify these shortcuts so I can pass them to robocopy via /xd.

1
  • What is the value of Attributes for the link? 525329? If you view the contents of the directory in Cmd / PowerShell (using -Force), does it contain a desktop.ini file and a target.lnk file? Commented Jun 1, 2021 at 17:28

2 Answers 2

1

It's a pain, since OneDrive uses its own type of NTFS ReparsePoint, so even the new versions of powershell don't have the tools to view the target, or really differentiate one from another. I did find they have a specific reparse point tag by using Get-ReparsePoint from the powershell community extensions module (pscx). In this case, Documents\ is a link to a sharepoint document library, and TestFolder\ is a folder created in windows explorer:

Get-ChildItem -Attributes ReparsePoint | Get-ReparsePoint

Path                                                            ReparsePointTag
----                                                            ---------------
C:\users\user\OneDrive - domain.com\Documents                   2415943706
C:\users\user\OneDrive - domain.com\Microsoft Teams Chat Files  2415943706
C:\users\user\OneDrive - domain.com\Notebooks                   2415943706
C:\users\user\OneDrive - domain.com\TestFolder                  2415976474
C:\users\user\OneDrive - domain.com\TestFolder\test.txt         2415943706
C:\users\user\OneDrive - domain.com\Test.txt                    2415943706

I converted the tag values to hex, and used this Microsoft Docs list of reparse point tags to see... not much, just that these are all OneDrive-related:

2415935514 = 0x9000401A = IO_REPARSE_TAG_CLOUD_4
2415943706 = 0x9000601A = IO_REPARSE_TAG_CLOUD_6
2415976474 = 0x9000E01A = IO_REPARSE_TAG_CLOUD_E

From the small amount of testing I did, I think you could use this to list directories with the ReparsePointTag of 2415943706 and feed them to your robocopy script to exclude them.

It might be a better idea to revisit using robocopy to back up a user's local onedrive files instead of something native to onedrive.

3
  • Thanks for this: Get-ReparsePoint looks like a way to at least identify these shortcuts. One assumes that the PowerShell cmdlets will be updated at some point to allow Get-ChildItem to identify them maybe via attributes/mode Commented Jun 7, 2021 at 12:41
  • Sadly, after returning to this many months later, all of the reparse points have the value 2415943706. The one that's a shortcut to another document library has the same tag :-( Commented Nov 29, 2021 at 18:03
  • Still looking for an answer to this :-( Commented Oct 24, 2022 at 12:40
1

I found a different way to do this, based on OneDrive setting the icon type for these shortcuts to a specific "link" icon:

screenshot

You can check each folder for a desktop.ini hidden system file that specifies IconResource=*OneDrive.exe,4 like this:

# get a list of folders in onedrive
$OneDriveDirs = Get-ChildItem $env:OneDrive -Recurse -Directory

# check each folder for the onedrive link icon
$OneDriveLinks = foreach ($folder in $OneDriveDirs) {
  if (Test-Path $folder\desktop.ini) {
    if ((Get-Content $folder\desktop.ini -Force) -match 'IconResource=.*OneDrive.exe,4') {
      $folder
    }
  }
}
$OneDriveLinks.FullName

# outputs
C:\Users\user\OneDrive - domain.com\Documents
C:\Users\user\OneDrive - domain.com\General

I checked the other onedrive icons and saw a second folder link icon at index 7, so maybe check for both?

icons

I'll also recommend using an actual backup service like veeam instead of backing up the locally-synced items. For example, what happens if the user wasn't logged into onedrive for a while?

4
  • Excellent bit of thinking outside of the box! Thanks - will look at implementing it... Because OneDrive is so flaky, in development I'm always backing up my OneDrive to network storage. However, the script has started copying all the projects and more importantly, I don't want them copied back! Commented Oct 25, 2022 at 17:31
  • Although to be honest, OneDrive has got a bit better in this area. It used to have a very nasty habit of dragging back long deleted folders & files if you happened to restore a very old image/snapshot. They seemed to have fixed that critical flaw. Commented Oct 25, 2022 at 17:34
  • On Windows 11, the icon index was 7 Commented Jan 18, 2023 at 11:18
  • I've added this into my robocopy based backup script and it works a treat. A little sketchy but it'll have to do until Microsoft implement some API/function to detect the shortcut folder Commented Jan 18, 2023 at 12:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .