Powershell script to get number of lists, list items, libraries, and documents in a given sharepoint online site

I just started using PowerShell 4 days ago, so this may just be a simple syntax issue I'm not understanding. I have some code that I've cobbled together here:

#sharepoint site url $Site = Get-SPOSite https://______________________ #variables $CountDocumentItems = 0 $CountDocumentLibray = 0 $CountListItems = 0 $CountList = 0 $Results = @() #Get Credentials to connect to SharePoint Admin Center $Cred = Get-Credential Function Get-SPOWeb($WebURL) < #Setup credentials to connect $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Get Web information and subsites $Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL) $Context.Credentials = $Credentials $Web = $Context.Web $Context.Load($Web) $Context.Load($Web.Webs) $Context.executeQuery() #Iterate through each subsite in the current web foreach ($Subweb in $Web.Webs) < #Get the web object $Subweb #Call the function recursively to process all subsites underneath the current web Get-SPOWeb($Subweb.url) >> $AllWebs = Get-SPOWeb $Site.Url foreach ($item in $AllWebs) < foreach($list in $item.Lists) < if ($list.BaseType -eq "DocumentLibrary") < $CountDocumentLibray = $CountDocumentLibray + 1 $CountDocumentItems = $list.ItemCount + $CountDocumentItems >else < $CountList = $CountList+1 $CountListItems = $list.ItemCount + $CountListItems >> $Results += New-Object PSObject -Property @ $CountDocumentItems = 0 $CountDocumentLibray = 0 $CountListItems = 0 $CountList = 0 > #$site.Dispose() $Results | Select 'Site Title', 'Document Library Count', 'Document Count', 'List Count', 'List Item Count' | Format-Table 

When I run it, it does not like the foreach($list in $item.Lists) line at all. I get alternating "The collection has not been initialized" errors with $list or $item.Lists being underlined. I've tried setting $item.Lists into a variable and looping through that variable with the same issue. When I just type $item. inside the first foreach it does give me Lists as an option. I am not really sure where to go from here. That whole foreach section came from someone trying to demonstrate looping through an SP site, not SPO, so perhaps I'm just trying to use the wrong properties entirely. But I don't know enough yet to understand what it is I do need. *Editing to add that after a whole bunch of that same error in a row, I do get a table output with the list of site titles, so $item.Title seems to be working fine. But all the counts are 0 because nothing else worked.