Wednesday 24 February 2010

CONFIGURING ULS LOGGING ON NON-DEFAULT DRIVE VIA POWERSHELL SCRIPT

CONFIGURING ULS LOGGING ON NON-DEFAULT DRIVE VIA POWERSHELL SCRIPT:

Here is a Powershell script to set the ULS Logging to a different drive. The script takes 2 parameters - the first is the log file location, the second is the number of log files to create:

Param([string]$logDirectory, [int]$number_of_log_files)
$description =@'

This script moves the trace logs to a specified directory and specifies the number of logfiles to maintain
'@

$scriptname = $MyInvocation.MyCommand.Name
$scriptpath = $MyInvocation.MyCommand.Path


$transcriptFile = "C:\Install\Logs\Powershell_$scriptname.log"
Start-Transcript $transcriptFile -append -force


Write-Output "Starting Script: $scriptpath"
Write-Output $description


$error.Clear()


$erroractionpreference="Stop"


$ReportErrorShowExceptionclass=$true


$ReportErrorShowInnerexception=$true


$ReportErrorShowSource=$true


$ReportErrorShowStackTrace=$true


trap {


$errorRecord = $error[0]


Write-Output "ErrorRecord:"


$errorRecord
Format-List * -Force
Out-Default


Write-Output "CategoryInfo:"


$errorRecord.CategoryInfo
Format-List * -Force
Out-Default


Write-Output "ErrorDetails:"


$errorDetails = $errorRecord.ErrorDetails


Write-Output "Message:"


$errorDetails.Message
Out-Default


Write-Output "RecommendedAction:"


$errorDetails.RecommendedAction
Out-Default


Write-Output "FullyQualifiedErrorId:"


$errorRecord.FullyQualifiedErrorId
Out-Default


Write-Output "InvocationInfo:"


$errorRecord.InvocationInfo
Format-List * -Force
Out-Default


Write-Output "TargetObject:"


$errorRecord.TargetObject
Format-List * -Force
Out-Default


Write-Output "Exception:"


$Exception = $errorRecord.Exception


for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))


{$Exception
Format-List * -Force
Out-Default}


Stop-Transcript


;break


}


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


New-Item $logDirectory -type directory -Force


$directoryInfo = New-Object System.IO.DirectoryInfo($logDirectory)


$directorySecurity = $directoryInfo.getaccesscontrol()


$fileSystemAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("$env:COMPUTERNAME\WSS_WPG",[System.Security.AccessControl.FileSystemRights]::FullControl,[System.Security.AccessControl.AccessControlType]::Allow)


#$fileSystemAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("dev\administrator",[System.Security.AccessControl.FileSystemRights]::FullControl,[System.Security.AccessControl.AccessControlType]::Allow)


$directorySecurity.AddAccessRule($fileSystemAccessRule)


$directoryInfo.SetAccessControl($directorySecurity)


$diagnosticsService = [Microsoft.SharePoint.Administration.SPDiagnosticsService]::Local


$diagnosticsService.LogLocation = $logDirectory


$diagnosticsService.LogCutInterval = $number_of_log_files


$diagnosticsService.Update()


Restart-Service "SPTrace"
#################################################################################


No comments:

Post a Comment

SharePoint Information Architecture Diagram

Here is the template I use for Information Architecture designs. It's built using Mindjet and I flesh the nodes out with the low level d...