Hi @tim christiansen ,
According to my research and testing, please try to use the following PowerShell code to sync a SharePoint site folder:
$WebURL = "https://tenantname.sharepoint.com/sites/"
$SiteName = "MySiteName"
$SiteID = "{my Site GUID}"
$WebID = "{my Web GUID}"
$ListID = "{my List GUID}"
# Give Windows some time to load before getting the email address
Start-Sleep -s 20
$UserName = $env:USERNAME
$Domain = "@yourdomain.com"
# Use a "Do" loop to check to see if OneDrive process has started and continue to check until it does
Do{
# Check to see if OneDrive is running
$ODStatus = Get-Process onedrive -ErrorAction SilentlyContinue
# If it is start the sync. If not, loopback and check again
If ($ODStatus)
{
# Give OneDrive some time to start and authenticate before syncing library
Start-Sleep -s 30
# set the path for odopen
$odopen = "odopen://sync/?siteId=" + $SiteID + "&webId=" + $WebID + "&webUrl=" + $webURL + $SiteName + "&listId=" + $ListID + "&userEmail=" + $UserName + $Domain + "&webTitle=" + $SiteName + ""
#Start the sync
Start-Process $odopen
}
}
Until ($ODStatus)
More information for reference:
how to sync a sharepoint 365 folder using a .bat or powershell?
Syncing SharePoint Document Libraries on Non-Persistent Virtual Computers
Hope it can help you. Thanks for your understanding.
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.