The target is to create a PowerShell script to sync files from SharePoint to a local server using a service account.
A new Website is created in SharePoint.
An additional document library is created.
- The default document library is used as source for the files to sync down
- the additional document library is used as place where the already synced files are moved to to avois overwriting
To Get Site Collection ID, hit this URL in the browser: https://.sharepoint.com/sites//_api/site/id
create app registration with permission "Files.ReadWrite.All" and "Sites.ReadWrite.All"
https://www.youtube.com/watch?v=7Bkv9J9mVr0 see .ps1 file, then upload to app registration
https://learn.microsoft.com/en-us/powershell/microsoftgraph/installation?view=graph-powershell-1.0
https://www.vcloudnine.de/use-app-only-authentication-with-the-microsoft-graph-powershell-sdk/
https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http
see .ps1 file
https://learn.microsoft.com/en-us/graph/api/driveitem-move?view=graph-rest-1.0&tabs=powershell
-
add & change custom metadata field
check status of custom matadata field "downloaded" Write-Host $file.ListItem.Fields.AdditionalProperties.downloaded
-
Compare Hash
https://superuser.com/questions/1643084/how-to-not-overwrite-existing-files
With Graph Permission on Sites.Selected and admin consent
POST https://graph.microsoft.com/v1.0/sites/{siteId}/permissions
Content-Type: application/json
{
"roles": ["write"],
"grantedToIdentities": [{
"application": {
"id": "<app id>",
"displayName": "<name of app>" // must not match
}
}]
}
https://blog.topedia.com/2022/08/sites-selected-berechtigung-in-sharepoint-und-microsoft-graph-api/