1

I created a script which iterates though all lists and it's folders and finds ones with unique permissions. Apart from the functionality I have I need to find these folders sizes and then compress them to ZIP including all sub folders and files.

Could you please check the script below and help me to figure out the task?

$rootSite = New-Object Microsoft.SharePoint.SPSite("https://mysharepoint.com/");

foreach ($site in $rootSite.WebApplication.Sites)
{

    $webs = Get-SPWeb $site.Url

    foreach($web in $webs)
    {

       $lists = $web.Lists

       foreach($list in $lists){

           if($list.HasUniqueRoleAssignments){

               $spQuery = New-Object Microsoft.SharePoint.SPQuery;

               $spQuery.ViewAttributes = "Scope='RecursiveAll'";

               $spQuery.Query = "<Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='ContentTypeId'>0x0120</Value></BeginsWith></Where>";

               $folders = $list.GetItems($spQuery);

               foreach($folder in $folders)
               {
                    if($folder.HasUniqueRoleAssignments){
                        foreach($item in $folder.RoleAssignments)
                        {
                            foreach($accessLevel in $item.RoleDefinitionBindings)
                            {
                                if ($accessLevel.Name -ne "Limited Access")
                                {
                                    Write-Host $web ";" $list ";" $folder.Url ";" $item.Member ";" $accessLevel.Name ";"
                                }
                            }

                        }

                    }

                }

            }

        }

    }

} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.