By using sharepoint power shell, how we can know all the users accessing sub-sites by using web analytics service
2 Answers
$Site=Get-SPSite http://sitename
foreach ($web in $site.AllWebs)
{
$siteUrl = $web.Url
$siteName = $web.Title
$siteUserCnt = $web.AllUsers.Count
$siteusage = $site.Usage.Storage/1MB
$Hits = $site.Usage.Hits
$Created = [datetime]$web.Created
$LastModified = $Web.LastItemModifiedDate
$SnapShot = (get-date)
$LastUpdate = ($SnapShot – [datetime]$LastModified)
$outputToCSV = New-Object PSObject -Property @{"Site Title" = $siteName
"Url" = $siteUrl
"Total Users" =$siteUserCnt
"Size" = $siteusage
"Date Last Modified" = $LastModified
"Days Last Update" = $LastUpdate
"Hits" =$Hits
"Date Created" =$Created
}
$outputToCSV | out-file -FilePath "E:\test2.csv" -Append
}
-
Dear Willman, Thank you for your reply, but I need to find out the window login of users access all the sub sites in site collection.– SPDevFeb 17, 2020 at 10:30
-
Hi dear Willman, let me rephrase my question, how we can get Top Visitor Report/ excel file for SharePoint 2010 site Usage Web Analytics Service by using sharepoint power shell command or script, Right now from Site Collection Analytics - To Visitor report we are getting only 2000 user names, where there should be more than 2000. how we can all the users how have accessed for last one year.– SPDevFeb 18, 2020 at 12:13
Here is the PowerShell code to get web analytics report in SharePoint 2010:
#-------------------------------------------------------------------------------------------
# Name: Get-WASummaryReport
# Description: This script will get the Web Analytics Summary Report
# Usage: Run the function with the required parameters
# Context can be SPWebApplication, SPSite or SPWeb
# By: Ivan Josipovic, softlanding.ca
#-------------------------------------------------------------------------------------------
Function Get-WASummaryReport($Context,$DaysToGoBack){
Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0;
[System.Reflection.Assembly]::Load("Microsoft.Office.Server.WebAnalytics, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null;
[System.Reflection.Assembly]::Load("Microsoft.Office.Server.WebAnalytics.UI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null;
Function DateTimeToDateId ([System.DateTime]$dt){
if (![System.String]::IsNullOrEmpty($dt.ToString())){
return [System.Int32]::Parse($dt.ToString("yyyyMMdd", [System.Globalization.CultureInfo]::InvariantCulture), [System.Globalization.CultureInfo]::InvariantCulture);
}else{
return 0;
}
}
#Not used in this report but other report types require it.
Function GetSortOrder([String]$sortColumn,[Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.OrderType]$order){
$SortOrders = New-Object System.Collections.Generic.List[Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.SortOrder];
$sortOrders.Add((New-Object Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.SortOrder($sortColumn, $order)));
return ,$SortOrders
}
$AggregationContext = [Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.AggregationContext]::GetContext($Context);
if (!$?){throw "Cant get the Aggregation Context";}
$viewParamsList = New-Object System.Collections.Generic.List[Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.ViewParameterValue]
$viewParamsList.Add((New-Object Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.ViewParameterValue("PreviousStartDateId", (DateTimeToDateId([System.DateTime]::UtcNow.AddDays(-($DaysToGoBack * 2)))))));
$viewParamsList.Add((New-Object Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.ViewParameterValue("CurrentStartDateId", (DateTimeToDateId([System.DateTime]::UtcNow.AddDays(-($DaysToGoBack)))))));
$viewParamsList.Add((New-Object Microsoft.Office.Server.WebAnalytics.ProcessedDataRetriever.ViewParameterValue("Duration", $DaysToGoBack)));
$dataPacket = [Microsoft.Office.Server.WebAnalytics.Reporting.FrontEndDataRetriever]::QueryData($AggregationContext, $null, "fn_WA_GetSummary", $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.DataTable
}
$WebApp = Get-SPWebApplication http://sp.client.com
$Site = Get-SPSite http://sp.client.com
$Web = Get-SPWeb http://sp.client.com
Get-WASummaryReport -Context $WebApp -DaysToGoBack 30
Get-WASummaryReport -Context $Site -DaysToGoBack 30
Get-WASummaryReport -Context $Web -DaysToGoBack 30
You can download the above code from the below MSDN gallery :
Get SharePoint Web Analytics using PowerShell Programmatically
-
Dear SP Expert, Thank you for your reply, but I need to find out the window login of users access all the sub sites in site collection.– SPDevFeb 17, 2020 at 10:30
-
Hi dear SP Expert, let me rephrase my question, how we can get Top Visitor Report/ excel file for SharePoint 2010 site Usage Web Analytics Service by using sharepoint power shell command or script, Right now from Site Collection Analytics - To Visitor report we are getting only 2000 user names, where there should be more than 2000. how we can all the users how have accessed for last one year.– SPDevFeb 18, 2020 at 12:12