I have found 100's of pages about getting groups, but best I can find about getting a list of all document is killing me!!

I have altered my script which works well with groups and tried to change it to documents.. but literally nothing is working for me.. executes and no errors

     $site = Get-SPOSite https://mysharepointsite.sharepoint.com/sites/construction
#Get all web sites in the site collections
$wc = $site.AllWebs
   foreach($w in $wc)
      write-host "in-loop-one" -foreground "magenta"
      #loopthrouh the lists and libraries in the site
      foreach($l in $w.Lists)
                write-host "in-loop-two" -foreground "magenta"
        #Check for only document libraries
        if($l.BaseTemplate -eq "DocumentLibrary")
                        write-host "in-if-three" -foreground "magenta"
            Write-Host $l.Title"(Web: "$w.Title")"


None of the write-host are triggering..

I have a document library called "documents" with 360 items in it.. I am trying to get a list of each of thoses documents..

can anyone point me in the right direction?

  • Did you copy that verbatim? There's an errant 1 on the second-to-last line there. Otherwise, are you sure that the call to Get-SPOSite is returning a site collection? If not, $site will be $null, and there will not be any $w in $wc. If $site -ne $null, there will be at least one SPWeb (namely $site.RootWeb), so the first Write-Host will display. Sep 11, 2017 at 16:49

1 Answer 1


The get-sposite cmdlet is available for SharePoint online, but check the docs for the object it returns, as it lacks anything for working with webs, lists, libraries, etc. Instead, we need to turn to either the CSOM or the PNP cmdlets (which use the CSOM).

A post that shows how to loop through webs via the CSOM is here.

Here's the docs for PNP for the command that returns all items from a given list. Again, see the docs, as other cmdlets are available for getting webs or lists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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