script-samples icon indicating copy to clipboard operation
script-samples copied to clipboard

Site object does not contain Usage property so export fails

Open mblennegard opened this issue 2 years ago • 3 comments

The script at https://github.com/pnp/script-samples/tree/main/scripts/spo-export-site-usage-reports fails. When checking it seems that the Site object (stored in the $Reports variable) does not contain the Usage property.

Has something changed between PnP.PowerShell versions? I have tested with PnP.PowerShell 1.12.0 and PnP.PowerShell 2.1.1, but same thing.

mblennegard avatar May 15 '23 11:05 mblennegard

@pkbullock i can investigate and fix if required

ValerasNarbutas avatar Aug 01 '23 17:08 ValerasNarbutas

I am having the same issue.

willobar avatar Nov 09 '23 19:11 willobar

Usage property can be retrieved

 foreach ($Report in $Reports) {
            try{
            $report = get-pnptenantsite -Identity $Report.Url -Detailed 
            Connect-PnPOnline -Url $Report.Url -Interactive
            $site = get-pnpsite -Includes Usage
            }
            catch{
                Write-Host "Error in getting site usage report:" $_.Exception.Message -ForegroundColor Red
            }
  <#Add desired properties to export by referencing
 $Site.Usage.Hits
}

However the value of $Site.Usage.Hits, $Site.Usage.Visits, etc.. are 0 except $Site.Usage.Storage and $Site.Usage.StoragePercentageUsed

I could not find out how to get these values, either the script can be amended to remove the usage data or comment added that the usage data are not returned for SharePoint Online.

reshmee011 avatar Jul 28 '24 22:07 reshmee011

Closing this, the API is limited in this space and cannot get the information needed.

pkbullock avatar Apr 12 '25 09:04 pkbullock