I am working on a Powershell script to automate SharePoint 2016 on-prem Popularity Trend reports. For this I'm using the SearchServiceApplication in conjunction with the method 'GetRollupAnalyticsItemData" which works fine to get total hits, unique users etc.
Now I am trying to get hits and users per day and per month. for this I found the methods 'GetHitCountForDay(DateTime)' and 'GetHitCountForMonth(DateTime)'.
It is working fine per month and I get expected output but I receive an error when trying to use the 'GetHitCountForDay' method. The error is:
Exception calling "GetHitCountForDay" with "1" argument(s): "Specified argument was out of the range of valid values.
Parameter name: date"
At C:\Users\****\Desktop\Untitled4.ps1:11 char:1
+ $result.GetHitCountForDay($FilterDate)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException
I tried to change the DateTime to only Date but that gives a different error entirely.
Expected output would be an integer number of the hits for that particular day (like it is with the month method where no errors are coming and I get an integer number of the monthly hits).
My Code:
searchApp = Get-SPEnterpriseSearchServiceApplication
$site = Get-SPSite http://sitecollection
$result = $searchApp.GetRollupAnalyticsItemData(1,[System.Guid]::Empty,$Site.ID,[System.Guid]::Empty)
$FilterDate = Get-Date "2018-12-20"
$result.GetHitCountForDay($FilterDate)
$result.GetHitCountForMonth($FilterDate)
Do I need to change the filterdate in any way or am I doing something wrong with the code?
Thanks
You are doing it right but data are stored only 14 days by default (which is maximum).
$ssp = Get-SPEnterpriseSearchServiceApplicationProxy
$config = $ssp.GetAnalyticsTenantConfiguration([Guid]::Empty)
$config.EventTypeDefinitions | ? { $_.EventTypeId -eq 1 }
Look for RecentPopularityTimeframe
.
Reference:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.