Can I unshare files in OneDrive with Powershell

Iron Contributor

I am looking through the cmdlets available in PnP-PowerShell and nothing is jumping out at me. What I want to do is loop through a given user's OneDrive - which I think I'm okay with - and then UNSHARE anything that's been shared. Or just set everything to Private if that's easier. 


Is this possible? With PnP, or maybe a POST to Graph, or any other way?



4 Replies

If you have Office 365 E5 go to Security & Compliance and first create a label to detect the content that you want, and auto-apply it on OneDrive locations, then create a DLP policy, select OneDrive locations (all or some users), in Policy settings select "Use advanced settings" -> Conditions: content is shared with people outside my organization -> Action: "Restrict access to the content for external users", then also select to notify user and send alerts to admins.

Or you can also use Cloud App Security: also with O365 E5

Thanks for the reply - this is good to know, though it doesn't really apply to my situation as I need to be able to script it and turn off the sharing even to internal users.


I did run through your directions, just to see what was possible and it can be done in our tenant which E3, in case that helps others.

Office 365 cloud app security file policies is only available for E5 subscriptions, you may see cloud app security portal, but no file policies.
The same is true for auto applying labels