SharePointEssentials is a PowerShell module that covers my basic usage of SharePoint. My goal is to keep my SharePoint commands in it. So far the only thing it can do is to synchronize files from local folder to SharePoint Online.
Install-Module SharePointEssentials -Force -Verbose
For this script to work, you need to have the following permissions on the application (as a minimum):
- Sharepoint / Sites.Selected
- Microsoft Graph / Sites.Selected
Of course you could run around with full control over all sites but that is not recommended.
Once you created application with minimal permissions you need to choose which sites should be covered under it.
$ClientID = '438511c4' # Temp SharePoint App
$Url = 'https://site.sharepoint.com/sites/TheDashboard'
# Lets connect to SharePoint Online
Connect-PnPOnline -Url $Url -Interactive
#First create a Read or Write permission entry for the app to the site. Currently unable to Set as FullControl
$WritePermissions = Grant-PnPAzureADAppSitePermission -Permissions "Write" -Site $Url -AppId $ClientID -DisplayName "Temp SharePoint App"
# Get the Permission ID for the app using App Id
$PermissionId = Get-PnPAzureADAppSitePermission -AppIdentity $ClientID
# Change the newly created Read/Write app site permission entry to FullControl
Set-PnPAzureADAppSitePermission -Site $Url -PermissionId $(($PermissionId).Id) -Permissions "FullControl"
Lets verify things worked as expected. You can do it by running the following command:
$ClientID = '438511c4' # Temp SharePoint App
$TenantID = 'ceb371f6'
#Connect-PnPOnline -Url $Url -ClientId $ClientID -ClientSecret $ClientSecret
Connect-PnPOnline -Url $Url -ClientId $ClientID -Thumbprint '2EC' -Tenant $TenantID
$FolderSiteRelativeUrl = "/Shared Documents" #Folder's Site Relative Path
$FolderItems = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeUrl -ItemType File -Recursive
$FolderItems | Format-Table
If everything works you can run the following command to synchronize files from local folder to SharePoint Online.
$Url = 'https://site.sharepoint.com/sites/SharePointEssentials'
$ClientID = '438511c4' # Temp SharePoint App
$TenantID = 'ceb371f6'
# Using certificate is not only recommended but required for this script to work, it seems ClientSecret is not working
Connect-PnPOnline -Url $Url -ClientId $ClientID -Thumbprint 'dfdfdf' -Tenant $TenantID
$SyncFiles = @{
SiteURL = 'https://site.sharepoint.com/sites/SharePointEssentials'
SourceFolderPath = "C:\Support\GitHub\SharePointEssentials\Examples\Reports"
TargetLibraryName = "Shared Documents"
LogPath = "$PSScriptRoot\Logs\Sync-FilesToSharePoint-$($(Get-Date).ToString('yyyy-MM-dd_HH_mm_ss')).log"
LogMaximum = 5
#Include = "*.aspx"
}
Sync-FilesToSharePoint @SyncFiles -WhatIf