Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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