0

i want to loop through all lists in all Site Collection and subsites in a SharePoint WebApplication and have Shell output only the files that end with .aspx. Here is my script so far:

$AllSites = Get-SPWebApplication https://contoso.de | Get-SPSite -Limit All | Get-SPWeb -Limit All
Foreach ($Site in $AllSites)

{
    $Lists = $Site.Lists
    Foreach ($List in $Lists)
    {
        
        $List.Items | ?
       
    }

}

I have looked online for over a week but i couldn't manage to find out how to list only the items that end with .aspx. I suppose it has to be after $List.Items where the question mark is. Can someone please help me figure out how to do this?

mklement0
  • 382,024
  • 64
  • 607
  • 775
RJ96
  • 303
  • 4
  • 13
  • What is the data type of the elements of `$List.Items`? (`$List.Items | Get-Member`) Which property of these elements contains the string that may end in `.aspx`? – mklement0 Mar 13 '23 at 15:43
  • Thanks for your reply @mklement0 - The data type of the elements in "$list.Items" is Microsoft.SharePoint.SPListItem. Tbh i am not sure which property contains the string that may end in ".aspx" but the idea here is that in some lists there are files that end with .aspx and these should then be displayed by PS. – RJ96 Mar 13 '23 at 16:00
  • 1
    I'm not familiar with SharePoint, but you can try the following: `$AllSites.Lists.Items | Where-Object { $_.File.ServerRelativeUrl -match '\.aspx$' }` – mklement0 Mar 13 '23 at 16:07

0 Answers0