Forum Discussion
Jake Turner
Oct 19, 2018Copper Contributor
Configure team sites to sync automatically to File Explorer
I've seen this shown in a video by Microsoft and the policy is available in my Group Policy editor. He called it Team Site Auto Mount. I have configured the policy, but with no success. Is this featu...
BinaryStars
Feb 24, 2023Copper Contributor
I have changed your script a bit to take into account the new powershell - love it when Microsoft change stuff 🙂
# source for this script
# https://www.blackforce.co.uk/2019/09/12/sharepoint-copy-library-id-missing-for-team-site-libraries-sync
# and
# https://www.blackforce.co.uk/2019/06/07/automatically-sync-microsoft-sharepoint-team-site-libraries-now-live#comment-4601075707
# Adapted by Dorje McKinnon to add a variable for the folder, because channels in team sites are specific to folders
# Adapted further by Ian Watson to take into account M$ changing the powershell modules
# This script was setup to sync the General channel folder from a departmental team site
#set the following four things for each SharePoint site / library / folder you want the Registry key for to auto sync with OneDrive
#example of the URL I'm synching https://MyTennant.sharepoint.com/sites/MyDepartment/Shared Documents/General
$siteName = 'MyDepartment' #Sharepoint site URL
$docLib = 'Documents' #Sharepoint Document Library name not address
$docLibUrl = 'Shared documents' #Sharepoint library URL
$docLibFolder = 'General'
#>>> Clean up old Modules and install the required modules for powershell - click yes to all when prompted
Uninstall-Module -Name SharePointPnPPowerShellOnline -AllVersions -Force
Install-Module -Name PnP.PowerShell
#>>> everything below here likely stays the same everytime you run the script
# info on howto get your tennant id
# https://tomtalks.blog/2015/09/how-to-get-your-office-365-tenant-id/
$tenant = 'MyTennant' # the first part of your tennant name XXXXX.sharepoint.com
$tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' #Tenant ID, can be retrieved from Azure AD or PowerShell under optional.
# >>>> Login using an account with access to the site.
# If you do not have MDA or modern auth then do not use the -SPOManagementShell switch
# You will need to accept the permissions after login if not done already
Connect-PnPOnline https://$tenant.sharepoint.com/sites/$siteName -Interactive
# Convert Tenant ID
$tenantId = $tenantId -replace '-','%2D'
# Convert Site ID
$PnPSite = Get-PnPSite -Includes Id | select id
$PnPSite = $PnPSite.Id -replace '-','%2D'
$PnPSite = '%7B' + $PnPSite + '%7D'
# Convert Web ID
$PnPWeb = Get-PnPWeb -Includes Id | select id
$PnPWeb = $PnPWeb.Id -replace '-','%2D'
$PnPWeb = '%7B' + $PnPWeb + '%7D'
# Convert List ID
$PnPList = Get-PnPList $docLib -Includes Id | select id
$PnPList = $PnPList.Id -replace '-','%2D'
$PnPList = '%7B' + $PnPList + '%7D'
$PnPList = $PnPList.toUpper()
# end product &folderId=ecc664be%2D3ca0%2D4a7b%2D8ec2%2Dd92be4bf4847
# Convert FolderID ID
$foldertotest = '/sites/'+$siteName+'/'+$docLibUrl+'/'+$docLibFolder
$PnPFolder = Get-PnPFolder -url $foldertotest -Includes UniqueId
$PnPFolder = $PnPFolder.UniqueId -replace '-','%2D'
$PnPFolder = '%7B' + $PnPList + '%7D'
$PnPFolder = $PnPFolder.toUpper()
# Enumerate the Full URL
$FULLURL = 'tenantId=' + $tenantId + '&siteId=' + $PnPSite + '&webId=' + $PnPWeb + '&listId=' + $PnPList + '&folderId=' + $PnPFolder + '&webUrl=https%3A%2F%2F' + $tenant + '%2Esharepoint%2Ecom%2Fsites%2F' + $siteName + '&version=1'
# Output the FULL URL To Copy and Paste
Write-Output 'List ID: '
[uri]::UnescapeDataString("$FULLURL")Dorje-McKinnon
Apr 02, 2023Iron Contributor
BinaryStars many thanks for sharing your update 🙂