Reputation: 743
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 & 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:
$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
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:
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
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.
Any ideas what I am doing wrong?
Upvotes: 0
Views: 3028
Reputation: 11
Reply by MS Support-
At this time, the only supported method to display usage data for SharePoint Online is through the GUI. You can find more information about this here: https://support.office.com/en-us/article/view-usage-data-for-your-sharepoint-site-2fa8ddc2-c4b3-4268-8d26-a772dc55779e
The information above is not acceptable
Upvotes: 1