1

I want to list all webs in one site collection via powershell and adapted this script from the internet:

Get-SPWebApplication http://site | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID, LastItemModifiedDate | Export-CSV C:\Varredura.csv -NoTypeInformation 

Now I want to list all items in all webs found, so that would mean another loop. Is there a way I could do this using the same script? I mean something like this:

 Get-SPWebApplication http://site | Get-SPSite -Limit All | Get-SPWeb -Limit All | Get-SPList -Limit All| GetSPListItem -Limit All | Select Title, URL, ID, ParentWebID, LastItemModifiedDate |

Also, just so I can understand this, what does the | means in the code exactly?

Thanks in advance.

2

There is no definition for get-splist mentioned in the second script. to get the list items from all the lists you have to loop through all the sub sites.

For your second question about "|": its is a delimiter to pass the result to the next expression/command. for example:

Task: Get list of processes and select top 10 items.

Solution:

Get-Process | Select-Object -first 10

so here it first process the query and get all the items then it passes the result to the next command and executed to get only the required number of results.

1

here is the script for the getting all the list items

# Get All Web Applications
$WebApps=Get-SPWebApplication
foreach($webApp in $WebApps)
{
    foreach ($SPsite in $webApp.Sites)
    {
       # get the collection of webs
       foreach($SPweb in $SPsite.AllWebs)
        {
            write-host $SPweb.title ":" $spweb.URL
               foreach($list in $web.lists)
               {
                  foreach($item in $list.items)
                      {
                         Write-Host $item.Title
                      }

               }
        }
    }
  }

Read more: http://www.sharepointdiary.com/2012/06/iterate-through-webapps-sitecollections-sites-lists-listitems.html#ixzz4WEvkzbYA

  • How could I do that but exporting to a CSV file instead of printing in the console? – ranbo Jan 19 '17 at 20:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.