Enable Usage Analysis Processing

This script configures the Usage Analysis Settings for a SharePoint 2007 farm.
It is based on the sourcecode of Gary Lapointe's "gl-setusageanalysis" extension for stsadm.




#########################################################################################
# This script configures the various settings for Usage Analysis Processing
# Bert Van Landeghem - 12/08/2010
#########################################################################################

    [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    [System.Reflection.Assembly]::Load("Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

#########################################################################################
# Enable Usage Analysis Processing
# Central Administration > Operations > Usage Analysis Processing
#########################################################################################

    $usagesettings = [Microsoft.SharePoint.Administration.SPWebService]::AdministrationService.UsageSettings
    $usageSettings.LoggingEnabled = $true
    $usageSettings.UsageProcessingEnabled = $true
    $usageSettings.LogFilesDirectory = "E:\Usage Analysis Processing"
    $usageSettings.NumberLogFiles = 30
    $startTime = [DateTime]::Parse("00:30AM")
    $endTime = [DateTime]::Parse("03:30AM")
    $usageSettings.SetProcessingInterval($startTime.Hour, $startTime.Minute, $endTime.Hour, $endTime.Minute);
    $usageSettings.Update()

#########################################################################################
# Configure Advanced Usage Analysis Processing 
# Shared Services Administration > Office SharePoint Usage Reporting: Usage reporting  
#########################################################################################

    # Get the SSP object via Reflection
    $AllBindings = [System.Reflection.BindingFlags]::CreateInstance ,
                    [System.Reflection.BindingFlags]::FlattenHierarchy ,
                    [System.Reflection.BindingFlags]::GetField ,
                    [System.Reflection.BindingFlags]::GetProperty ,
                    [System.Reflection.BindingFlags]::IgnoreCase ,
                    [System.Reflection.BindingFlags]::Instance ,
                    [System.Reflection.BindingFlags]::InvokeMethod ,
                    [System.Reflection.BindingFlags]::NonPublic ,
                    [System.Reflection.BindingFlags]::Public ,
                    [System.Reflection.BindingFlags]::SetField ,
                    [System.Reflection.BindingFlags]::SetProperty ,
                    [System.Reflection.BindingFlags]::Static
    $ServerContext = [Microsoft.Office.Server.serverContext]::Default
    $sharedServiceProvider = $ServerContext.GetType().GetProperty("SharedResourceProvider", $AllBindings).GetValue($ServerContext, $null);

#########################################################################################
# Processing Settings: Enable advanced usage analysis processing. 
#########################################################################################

    $enable = $true
    $configurationType = [Type]::GetType("Microsoft.SharePoint.Portal.Analytics.Configuration, Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    [Type[]] $ArgumentTypeArray = $sharedServiceProvider.GetType(), [bool]
    [object[]] $ArgumentArray = $sharedServiceProvider, $enable
    $methodinfo = $configurationType.GetMethod("SetAnalyticsEnabledOnSrp",$AllBindings,$null,$ArgumentTypeArray,$null);
    $methodinfo.invoke($null, $ArgumentArray)

#########################################################################################
# Search Query Logging: Enable search query logging. 
#########################################################################################

    $enable = $true
    $queryLoggerType = [Type]::GetType("Microsoft.Office.Server.Search.Query.QueryLogger, Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    [Type[]] $ArgumentTypeArray = $sharedServiceProvider.GetType(), [bool]
    [object[]] $ArgumentArray = $sharedServiceProvider, $enable
    $methodinfo = $queryLoggerType.GetMethod("SetQueryLoggingEnabledOnSsp",$AllBindings,$null,$ArgumentTypeArray,$null);
    $methodinfo.invoke($null, $ArgumentArray)

 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s