Data / Provision

Register and login to SharePoint using an app

This script sample shows how to register an app in SharePoint and login to SharePoint using the app.

Summary

This script shows how to register an app in Azure Entry ID, login to SharePoint Online and set files links expiration in days.

Implementation

  • Open Windows PowerShell
  • Edit Script and add required parameters for Site URL, tenant
  • Press run
powershell

###### Declare and Initialize Variables ######  

$tenant = "[tenant].onmicrosoft.com"
$url="https://[tenant].sharepoint.com/sites/[site name]"

###### Register an app in Azure Entry ID, store command in result to be able access certificate ######
$result = Register-PnPEntraIDApp -ApplicationName "PnP Rocks" -Tenant $tenant -interactive

Connect-PnPOnline $url -ClientId $result.'AzureAppId/ClientId'  -Tenant $tenant -CertificatePath $result.'Pfx file'

###### Set files links expiration in days ######
Set-PnPTenantSite -identity $url -RequestFilesLinkExpirationInDay 50

Contributors

Author(s)
Valeras Narbutas

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Tool documentation & references

Keep exploring