0

I need to get a list of all files, older then 5 years, from few thousands sharepoint online sites and I am trying to do it by powershell script.
The problem I am having is that I have to reconnect with Disconnect/Connect-PnPOnline for each site which causes server to stop responding after few hundreds sites.

  foreach($site in $sites){
     $surl = $site.SiteUrl ; $sid = $site.ID
     $gcon =  Connect-PnPOnline -Url $surl -ClientId $GLClientId -ClientSecret $GLSecret -ReturnConnection  # Connection via Global SP app to read current site
     Get-PnPListItem -List $folder  -PageSize 500 -Connection $gcon | ForEach-Object{
       if($_.FileSystemObjectType -like "*File*"){        $f=$_; 
            if($t_TooOldDate -gt $f.FieldValues.Last_x0020_Modified){ ### 
                 $a_files+=[pscustomobject]@{'File'=$f.FieldValues.FileRef; 'Size'= $f.FieldValues.File_x0020_Size ; 'LastModified'=$f.FieldValues.Last_x0020_Modified}
                 $co++ ; $ts+= $f.FieldValues.File_x0020_Size
              } 
           }
        }
      Disconnect-PnPOnline -Connection $gcon
    }

So I am wandering if I could use same connection for the whole script and just keep changing site name?
Or maybe there is a better way to do it?

Thanks

user3195616
  • 195
  • 2
  • 13
  • REad Wiki article : https://en.wikipedia.org/wiki/Universal_Plug_and_Play?force_isolation=true. Article says it is using HTTP which mean the connection closes after each request/response. Your conclusion for reconnect does not make any sense. You are the client and the server doesn't know that you previously connected to a few hundred sites. I suspect your app have a memory leak. Check Event viewer while app is running and see if memory constantly increases. – jdweng May 11 '23 at 08:57

0 Answers0