title: Get SharePoint Online Site Collection Usage Data with PnP
body: <p>I am about to create a detailed report of all site collections on a tenant.
  One part of the report is the usage data such as hits &amp; visits. The report always returns 0 for these properties. I thought there might be a delay between the actual hit/visit and the report, so I tried it several times.
  Here is my script:</p>
  
  <pre><code>$adminSiteUrl = "https://tenant-admin.sharepoint.com";
  Connect-PnPOnline -Url $adminSiteUrl -Credentials 'O365Dev'
  $sites = Get-PnPTenantSite -Detailed
  Write-Host "Site Collections found: " $sites.Count
  $siteDirectory = @()
  
  foreach ($site in $sites)
  {
  $tenantSite = $sites | Where-Object {$_.Url -eq $site.Url}
  
  $siteDirectoryEntry = New-Object psobject
  Connect-PnPOnline -Url $site.Url -Credentials 'O365Dev'
  $siteDetails = Get-PnPSite -Includes RootWeb.Created, RootWeb.SiteUsers, RootWeb.Webs, GeoLocation, IsHubSite, LockIssue, Owner, SecondaryContact, Usage; $siteDetails
  
  
  $siteDirectoryEntryProperties = @{
      URL = $siteDetails.Url
      Title = $tenantSite.Title
      Description = $tenantSite.Description
      ...
      UsageBandwidth = $siteDetails.Usage.Bandwidth
      UsageHits = $siteDetails.Usage.Hits
      UsageVisits = $siteDetails.Usage.Visits
      }
  $siteDirectoryEntry = New-Object psobject -Property $siteDirectoryEntryProperties
  
  $siteDirectory += $siteDirectoryEntry
  }
  $siteDirectory | Export-Csv .\SiteDirectory.csv
  </code></pre>
  
  <p>I also tried to add "Usage.Hits" to the "Includes" argument of Get-PnPSite as I would do with other properties such as RootWeb. While it works for the latter, it throws the following error for any UsageInfo Properties:</p>
  
  <blockquote>
    <p>Get-PnPSite : The query expression is not supported.
    At C:\Users....\SPO_Reports.ps1:19 char:20
    + ... teDetails = Get-PnPSite -Includes RootWeb.Created, RootWeb.SiteUsers, ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : WriteError: (:) [Get-PnPSite], InvalidQueryExpressionException
        + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Site.GetSite</p>
  </blockquote>
  
  <p>I know I can get some usage statistics like storage through Get-PnPTenantSite but when it comes to hits and visits, it seems like this would be the only way.</p>
  
  <p>Any ideas what I am doing wrong?</p>