Open Office documents in the Client
Ensure that office documents will open in the desktop client application if such is installed
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!"
}
# 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)
# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
m365 login
}
# Get all enabled features from SharePoint site
$allEnabledFeatures = m365 spo feature list --webUrl $siteUrl --scope $featureScope | ConvertFrom-Json
# Get feature from enabled features
$spfeature = $allEnabledFeatures | Where-Object { $_.DefinitionId -eq $featureId }
# Check if feature found or not
if($spfeature.DefinitionId -eq $null) {
Write-host "Activating Feature ($featureId)..."
# Activate the site feature
m365 spo feature enable --webUrl $siteUrl --id $featureId --scope $featureScope
Write-host -f Green "Feature ($featureId) has been activated Successfully!"
}
else {
Write-host "Feature ($featureId) is already active on this site!"
}
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.
Tool documentation & references
- Want to learn more about PnP PowerShell and the cmdlets
Check out the PnP PowerShell site to get started and for the reference to the cmdlets.
- Want to learn more about CLI for Microsoft 365 and the commands
Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.