Skip to content

Instantly share code, notes, and snippets.

@NielsS79
Last active March 14, 2022 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NielsS79/3baa510850f0876d02af9e107419a186 to your computer and use it in GitHub Desktop.
Save NielsS79/3baa510850f0876d02af9e107419a186 to your computer and use it in GitHub Desktop.
How to influence OneDrive's Known Folder Move and target specific cloud folders. Part of a blog series on https://allthingscloud.blog.
<#
.SYNOPSIS
Mark the OneDrive folder '\Documen-ta-daa' as the target for the 'Documents'-folder during KFM.
.DESCRIPTION
This script is part of the blog series on OneDrive's Known Folder Move and how to influence it.
Please visit https://allthingscloud.blog/onedrive-and-its-unknown-folder-move-kfm-part-1/ and https://allthingscloud.blog/onedrive-and-its-unknown-folder-move-kfm-part-2/ for more information.
.NOTES
Author: Niels Scheffers <niels.scheffers@etesian.nl>
Last modified: 2022-03-14
#>
$siteUrl = 'https://notreally-my.SharePoint.com/personal/n_scheffers_alsonotreally_nl';
$documentsFolderName = 'Documen-ta-daa';
Import-Module -Name PnP.PowerShell;
Connect-PnPOnline -Url $siteUrl -Interactive;
$siteCtx = Get-PnPContext;
$documentsList = Get-PnPList -Identity 'Documents';
if ($siteCtx -and $documentsList) {
$documentsListUrl = $documentsList.RootFolder.ServerRelativeUrl;
$documentsFolderUrl = "$($documentsListUrl)/$($documentsFolderName)";
$documentsFolder = Get-PnPFolder -Url $documentsFolderUrl;
$siteCtx.Load($documentsFolder.ListItemAllFields);
$siteCtx.ExecuteQuery();
if ($documentsFolder) {
$documentsFolderGuid = $documentsFolder.ListItemAllFields.FieldValues['UniqueId'];
if ($documentsFolderGuid) {
$documentsList.RootFolder.Properties['vti_DocumentsFolderGuid'] `
= $documentsFolderGuid.ToString();
$documentsList.RootFolder.Update();
$siteCtx.ExecuteQuery();
}
}
}
<#
.SYNOPSIS
Other KFM properties in OneDrive that can be used as described in the other script in this Gist.
.DESCRIPTION
This script is part of the blog series on OneDrive's Known Folder Move and how to influence it.
Please visit https://allthingscloud.blog/onedrive-and-its-unknown-folder-move-kfm-part-1/ and https://allthingscloud.blog/onedrive-and-its-unknown-folder-move-kfm-part-2/ for more information.
.NOTES
Author: Niels Scheffers <niels.scheffers@etesian.nl>
Last modified: 2022-03-14
#>
$documentsList.RootFolder.Properties['vti_DesktopFolderGuid'];
$documentsList.RootFolder.Properties['vti_DocumentsFolderGuid'];
$documentsList.RootFolder.Properties['vti_CameraRollFolderGuid'];
$documentsList.RootFolder.Properties['vti_ScreenShotsFolderGuid'];
$documentsList.RootFolder.Properties['vti_PhotosFolderGuid'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment