Hi Ivan , I Ran the script on our Development Server , its working fine there . But when i am running the same script on production server , I am getting below error . Exception calling "GetContext" with "1" argument(s): "<nativehr>0x80070003</nativeh r><nativestack> </nativestack>" At D:\Scripts\WebA nalytics.ps1:27 char:119 + $AggregationCon text = [Microsoft.Offi ce.Server.WebAn alytics.Process edDataRetriever .AggregationCon text]::GetConte xt <<<< ($Context); + CategoryInfo : NotSpecified: (:) [], MethodInvocatio nException + FullyQualifiedE rrorId : DotNetMethodExc eption Cant get the Aggregation Context At D:\Scripts\WebA nalytics.ps1:28 char:19 + if (!$?){throw <<<< "Cant get the Aggregation Context";} + CategoryInfo : OperationStoppe d: (Cant get the Aggregation Context:String) [], RuntimeExceptio n + FullyQualifiedE rrorId : Cant get the Aggregation Context I am running the script with Farm Account . You told previously to make sure that the Web analytics Service Application is connected to the Web Application that the site is in.How to do that ? I checked following thing . Go to Central Admin -> Manage web applications->C lick on Web Application ->Service Connections ->Web Analytics Service Application is checked or not ?
Hi Ivan, Could you please tell me, How to pass custom date parameter to this script. I would like to get the report from Jan -01- 2016 to Jan -31 - 2016 and Feb-1-2016 to Feb-29-2016. I want to generate monthly report.
I've logged into my SharePoint server and tried running the script. When the code gets to line 29 to retrieve the $AggregationContext, I get an error message: Exception calling "GetContext" with "1" argument(s): "Object reference not set to an instance of an object." I've checked that the $Context object exists by using a write-output of the context of the web application, and it does print out the DisplayName and url of the webapp. I'm also running it with admin privileges and have checked that the WebAnalytics DLLs do exist in the assembly. Any other ideas on why it is not able to find the context? Thanks, Victor
Try running the script with the Farm Account. Also make sure that the Web analytics Service Application is connected to the Web Application that the site is in.
I've slightly modified the script to try and get the Top Visitors report for the web application. # Create parameters list $viewParamsList = New-Object System.Collections.Generic.Lis t[Microsoft.Off ice.Server.WebA nalytics.Proces sedDataRetrieve r.ViewParameter Value] $viewParamsList .Add((New-Objec t Microsoft.Offic e.Server.WebAna lytics.Processe dDataRetriever. ViewParameterVa lue("StartDateI d", (DateTimeToDate Id($ReportStart Date))))); $viewParamsList .Add((New-Objec t Microsoft.Offic e.Server.WebAna lytics.Processe dDataRetriever. ViewParameterVa lue("EndDateId" , (DateTimeToDate Id($ReportEndDa te))))); $dataPacket = [Microsoft.Offi ce.Server.WebAn alytics.Reporti ng.FrontEndData Retriever]::Que ryData($Aggrega tionContext, $null, "fn_WA_GetTopVi sitors", $viewParamsList , $null, $null, 1, 25000, $False); if (!$?){throw "Unable to get the Data. Try running the script as the Farm Account. If that doesnt work, make sure that the Web Analytics Service Application is connected to the Web Application and that the Site Web Analytics reports work through the browser.";} return $dataPacket.Dat aTable The script doesn't throw any errors or display any data. The only thing I've really changed is that the method accepts the start date and end date as parameters and I'm calling fn_WA_GetTopVis itors instead of fn_WA_GetSummar y. Any ideas on how I can get this to work so that it returns the Top Visitors report for the web application I'm passing into it?
I gave up on this and found another solution that meets my needs. Here's a sample snippet from my code: $server = "CentralAdminUrl" $webAppName = "MyWebApp" $sd = 01/01/2015 $ed = 01/31/2015 $wc = New-Object System.Net.WebC lient $wc.Credentials = [System.Net.Cre dentialCache]:: DefaultCredenti als $url = $server+ "/_layouts/WebA nalytics/Report .aspx?t=TopVisi torsReport&l=wa &id=https%3a%2f %2f"+$id+"%2f&W ebAppName="+$we bAppName+"&CD=t rue&SD="+$sd+"& ED="+$ed+"&SHOW ANALYZETAB=1&Ex port=1" $file = "d:\Logs\$(get- date -f yyyy-MM)-WebApp -TopVisitors.cs v" $wc.DownloadFil e($url, $file) Go in Central Admin on your SharePoint server and look at the URL for the web analytics reports. You can just create a web client object in your code and use that url to get the report.
Hi Ivan, Thanks for the script. I tried this and it worked fine. I want to export the report in CSV file, I tired some commands but I am not able to export the DataTable in CSV. Can you help me out?
I used this: $dt = Get-WASummaryReport -Context $web -DaysToGoBack 30 $dt | export-csv toFile.csv -NoTypeInformat ion
I would love to see a similar script for SharePoint 2013 as there's literally nothing out there at the moment. Thanks.
Hi! I created a CodePlex project with similar functionality for SharePoint 2013. Hopefully this is useful to others! SharePoint 2013 Web Analytics Data Export to CSV using PowerShell https://sp2013wade.codeplex.co m
Could you show a little example showing the usage of the getsortOrder method please. Thank you in advance.