Set documents to View Only using pnp

Copper Contributor

Hello,

I have set up a document library that has approval before publishing but find that editors often accidently edit documents - setting them back to a Draft.

How can I set documents using pnp to open as View Only as the default?

 

Thanks

Rosie 

1 Reply

@Rosie Horn You're facing an issue where editors in a specific SharePoint Online document library are accidentally editing and setting documents back to draft mode, despite having an approval process in place.

 

To mitigate this, you've requested a way to set documents to open as "View Only" by default using PnP PowerShell. To address this requirement, I'll connect to your SharePoint Online tenant using the Connect-PnPOnline cmdlet, specifying the appropriate tenant and site URLs. Then, I'll identify the document library and any specific folders or documents that need to be set to "View Only" mode. Next, I'll leverage the Get-PnPFolderItem cmdlet to retrieve the targeted folder or document, followed by the Set-PnPFileProperty cmdlet. This cmdlet will allow me to set the "OpenInClient" property to "ReadOnly" for the specified items, ensuring they open in a view-only mode by default. If you prefer to apply this setting to all documents within the library, I can omit the folder URL parameter, effectively setting the "OpenInClient" property to "ReadOnly" for the entire document library.

 

It's important to note that this configuration will only affect the default behavior when opening documents from SharePoint in client applications like Word, Excel, or PowerPoint. Users with appropriate permissions will still have the ability to edit documents if they choose to do so from within the client application itself. Throughout this process, I'll ensure that the appropriate tenant, site, and document library information is accurately provided, and I'll be vigilant in monitoring any potential issues or unintended consequences of the configuration changes.