Skip to content

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.

Notifications You must be signed in to change notification settings

EvotecIT/SharePointEssentials

Repository files navigation

SharePointEssentials

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.

Installation

Install-Module SharePointEssentials -Force -Verbose

Usage Synchronization

Permissions required

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.

Permissions assigned

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"

Verify that it worked

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

Example

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

Credits

About

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.

Topics

Resources

Stars

Watchers

Forks