OneDrive - deleting unique permissions

Anonymous
2019-01-08T19:49:03+00:00

How can you delete the unique permissions from multiple files/folders? It seems you have to go to each file and do it, there's no way to select multiples and manage the permissions.

Microsoft 365 and Office | OneDrive | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2019-01-09T02:03:27+00:00

Hi 1440,

You can use SharePoint CSOM to break unique permissions on all folders and files in the OneDrive for Business library and then reset permissions on the folders and files you like via the following steps.

  1. Install SharePoint Online Management Shell and connect to SharePoint Online in SharePoint Online Management Shell via the steps in the article. Meanwhile, download SharePoint Server 2013 Client Components SDK.
  2. Save the following to a .ps1 file.

Note: Change the corresponding information in the file. Username and password are the global administrator’s username and password. URL is the personal site’s URL.

replace these details (also consider using Get-Credential to enter password securely as script runs).. 

$username = "xxx" 

$password = "xxx" 

$url = "xxx"

$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force 

the path here may need to change if you used e.g. C:\Lib.. 

Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 

Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

note that you might need some other references (depending on what your script does) for example:

Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll" 

connect/authenticate to SharePoint Online and get ClientContext object.. 

$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url) 

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword) 

$clientContext.Credentials = $credentials 

if (!$clientContext.ServerObjectIsNull.Value) 

{ 

    Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green 

}

  1. Run the .ps1 file in SharePoint Online Management Shell.
  2. Save the following to a .ps1 file.

Note: Change the corresponding information in the file. When executing the .ps1 file, type the desired user’s username and password instead.

#Load SharePoint Online Assemblies

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#To call a non-generic method Load

Function Invoke-LoadMethod() {

    param(

            [Microsoft.SharePoint.Client.ClientObject]$Object = $(throw "Please provide a Client Object"),

            [string]$PropertyName

        )

   $ctx = $Object.Context

   $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load")

   $type = $Object.GetType()

   $clientLoad = $load.MakeGenericMethod($type)

   $Parameter = [System.Linq.Expressions.Expression]::Parameter(($type), $type.Name)

   $Expression = [System.Linq.Expressions.Expression]::Lambda([System.Linq.Expressions.Expression]::Convert([System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName),[System.Object] ), $($Parameter))

   $ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1)

   $ExpressionArray.SetValue($Expression, 0)

   $clientLoad.Invoke($ctx,@($Object,$ExpressionArray))

}

##Variables for Processing

$SiteUrl = "xx"

$ListName= "Documents"

#Get Credentials to connect

$Cred= Get-Credential

$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Set up the context

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)

$Context.Credentials = $Credentials

 

Thanks,

Cliff

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2019-01-10T09:11:13+00:00

    Hi 1440,

    If you need further help on this issue, welcome to post here at your convenience.

    Thanks,

    Cliff

    Was this answer helpful?

    0 comments No comments