Pergunta

I am getting the below error:

The following exception occurred while trying to enumerate the collection: "Access is denied. 
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))".
At line:35 char:19
+   foreach($Web in $Site.AllWebs)
+                   ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : ExceptionInGetEnumerator

When I run:

#Get Size of all Sub-sites in a Site Collection
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

# Function to calculate folder size
Function CalculateFolderSize($Folder)
{

$ErrorActionPreference = "SilentlyContinue" 
    [long]$FolderSize = 0

    foreach ($File in $Folder.Files)
    {
   #Get File Size
        $FolderSize += $file.TotalLength;

  #Get the Versions Size
        foreach ($FileVersion in $File.Versions)
        {
            $FolderSize += $FileVersion.Size
        }
    }
 #Iterate through all subfolders
    foreach ($SubFolder in $Folder.SubFolders)
    {
  #Call the function recursively
        $FolderSize += CalculateFolderSize $SubFolder  
    }
    return $FolderSize
}


$SiteURL = "https://myurl.com.mt/"
$Site = new-object Microsoft.SharePoint.SPSite($SiteURL)

  foreach($Web in $Site.AllWebs)
  { 
    #Call function to calculate Folder Size
    [long]$WebSize = CalculateFolderSize($Web.RootFolder)

    #Get Recycle Bin Size
    foreach($RecycleBinItem in $Web.RecycleBin)
        {
           $WebSize += $RecycleBinItem.Size
        }

        $Size = [Math]::Round($WebSize/1MB, 2)
        Write-Host  $web.Url ":`t" $Size "MB"

    #Dispose the object
    $web.dispose()
   }

I am trying to get the size of each and every sub-site inside a site collection.

I have tried this same script on another site collection and it worked so it must not be something from the code.

Am I missing something from my end?

I am using SharePoint 2013 on-premise (farm)

Foi útil?

Solução

Solved this by adding myself as Farm Admin with Full Read/Full Control rights on the Web Application through Central Administration -> Web Application Management -> User Policy

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top