Skip to content

Instantly share code, notes, and snippets.

@plamber
Created October 2, 2021 04:02
Show Gist options
  • Select an option

  • Save plamber/76f305b6cf847733f067ed8dff7f3528 to your computer and use it in GitHub Desktop.

Select an option

Save plamber/76f305b6cf847733f067ed8dff7f3528 to your computer and use it in GitHub Desktop.
Retrieve the Known Folder Move Directories from a OneDrive site
### Example on how to retrieve the Known Folder Move Directories from a OneDrive site
### This script is using PNP PowerShell to perform the activity
$url = "OneDriveUrl"
Connect-PnPOnline $url
function Get-FolderUrl ($context, $list, $valueToCheck) {
if ($list.RootFolder.Properties.FieldValues.ContainsKey($valueToCheck)) {
$item = $list.GetItemByUniqueId($list.RootFolder.Properties.FieldValues[$valueToCheck])
$context.Load($item)
$context.ExecuteQuery()
return $item["FileRef"]
}
return ""
}
$context = Get-PnPContext
$list = Get-PnPList "Documents"
$context.Load($list.RootFolder.Properties)
$context.ExecuteQuery()
[pscustomobject]@{
"onedriveUrl" = $url
"desktopFolderRelativeUrl" = Get-FolderUrl $context $list "vti_DesktopFolderGuid"
"documentsFodlerRelativeUrl" = Get-FolderUrl $context $list "vti_DocumentsFolderGuid"
"photosFolderRelativeUrl" = Get-FolderUrl $context $list "vti_PhotosFolderGuid"
"cameraFolderRelativeUrl" = Get-FolderUrl $context $list "vti_CameraRollFolderGuid"
"screenshotsFolderRelativeUrl" = Get-FolderUrl $context $list "vti_ScreenShotsFolderGuid"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment