Open Office documents in the Client
Summary
One of the most common requests from customers is that any office document in SharePoint site should open in the desktop client application so here goes:
Implementation
- Open VS Code
- Create a new file
- Write a script as below
- Change the variables to target to your environment
- Run the script
Screenshot of Output
# SharePoint online site url
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"
# Scope of feature: Web or Site
$featureScope = "Site"
# SharePoint Feature ID: in this case "Open Documents in Client Applications by Default (OpenInClient)"
$featureId = "8a4b8de2-6fd8-41e9-923c-c7c3c00f8295"
# Another common scenario is Activating Document ID feature (Feature ID: b50e3104-6812-424f-a011-cc90e6327318)
# Connect to SharePoint Online site
Connect-PnPOnline -Url $siteUrl -Interactive
# Get Feature from SharePoint site
$spFeature = Get-PnPFeature -Scope $featureScope -Identity $featureId
# Check if feature found or not
if ($spFeature.DefinitionId -eq $null) {
Write-host "Activating Feature ($featureId)..."
# Activate the site feature
Enable-PnPFeature -Scope $featureScope -Identity $FeatureId -Force
Write-host -f Green "Feature ($featureId) has been activated Successfully!"
}
else {
Write-host "Feature ($featureId) is already active on this site!"
}
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Kasper Larsen, Fellowmind |
Ganesh Sanap |
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.