18/09/2013

SharePoint portalsuperreaderaccount and portalsuperuseraccount

Get and Set super reader and super user accounts


How to get and set the SharePoint portalsuperreaderaccount and portalsuperuseraccount:

$w = Get-SPWebApplication "url"
$w.properties["portalsuperuseraccount"] = "domain\username"
$w.properties["portalsuperreaderaccount"] = "domain\username"
$w.Update()
Write-Host "superreader: " $w.properties["portalsuperreaderaccount"]
Write-Host "superuser: " $w.properties["portalsuperuseraccount"]


Error message that can appear if not properly set:

Object Cache: The super reader account utilized by the cache does not have sufficient permissions to SharePoint databases.
To configure the account use the following command 'stsadm -o setproperty -propertyname portalsuperreaderaccount -propertyvalue account -url webappurl'. It should be configured to be an account that has Read access to the SharePoint databases.
 Additional Data:
 Current default super reader account: NT AUTHORITY\LOCAL SERVICE


Or this error message

Trying to store a checked out item (/PAGES/PAGENAME.ASPX) in the object cache.  This may be because the checked out user is accessing the page, or it could be that the SharePoint system account has the item checked out.  To improve performance, you should set the portalsuperuseraccount property on the web application.  See the documentation for more information.

05/09/2013

Generate Excel content with PowerShell

Prerequisites

  • Excel must be installed
  • If the Excel file shall be generated and saved in a scheduled task some folders must be created: C:\Windows\System32\config\systemprofile\Desktop (32 bit and 64 bit) and C:\Windows\SysWOW64\config\systemprofile\Desktop (64 bit)

Open an existing Excel file

Using-Culture en-us {

 # open existing file
 $excelFilePath = "path" + "fileName.xls"
 $Excel = New-Object -COM Excel.Application
 $Excel.visible = $False
 $Excel.DisplayAlerts = $False
 $Excel.Workbooks.Open($excelFilePath)

 
 # create new sheet and activate it
 $sheet = $Excel.sheets.Add()                                                   
 $sheet.Name = "sheetName"
 $sheet.activate()

 
 # clean up
 Remove-ComObject -Verbose

}

Help functions

function Using-Culture ([System.Globalization.CultureInfo]$culture, [ScriptBlock]$script)
{
 $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
 trap
 {
  [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
 }
 [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
 $ExecutionContext.InvokeCommand.InvokeScript($script)
 [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}


function Remove-ComObject {
 [CmdletBinding()]
 param()
 end {

  Start-Sleep -Milliseconds 500
  [Management.Automation.ScopedItemOptions]$scopedOpt = 'ReadOnly, Constant'
  Get-Variable -Scope 1 | Where-Object {
   $_.Value.pstypenames -contains 'System.__ComObject' -and -not ($scopedOpt -band $_.Options)
  } | Remove-Variable -Scope 1 -Verbose:([Bool]$PSBoundParameters['Verbose'].IsPresent)
    [gc]::Collect()
  }
}


Data

# Retrieve cell (1,1) and set the value Name
$sheet.Cells.Item(1,1) = "Name"


# Clear data from a given range
$range = $sheet.Range("a1","e1000")
$range.clear()


Formatting

# Indent cell (1,1) 4 times
$sheet.Cells.Item(1,1).AddIndent = $true
$sheet.Cells.Item(1,1).IndentLevel = 4


# set Bold text on a row
$sheet.Rows.Item(1).Font.Bold = $true


# set Font size on a given range
$range = $sheet.Range("a1","e1000")
$range.Font.Size = 12     


# set Font style on row 1
$sheet.Rows.Item(1).Style = "Heading 2"


# set column width in cell (1,1)
$sheet.Cells.Item(1,1).columnwidth=40

03/09/2013

SharePoint 2010 Surveys - incomplete results

List the user of all Incomplete Survey Results

Incomplete results means that a user has pressed Save and Close in the Survey instead of Finish.
  1. Find Site ID for the Survey Site
    • Central Admin > Change Site Collection administrators
    • Change site collection and the site id will appear in the URL
  2. Find List ID for the Survey
    • List Settings > Audience Targeting
    • Copy the list ID from the URL
  3. Run DB Query:
Select userdata.tp_author,
(Select tp_Title from UserInfo where UserInfo.tp_ID=userdata.tp_author and tp_siteID='siteid')
As UserName from USERDATA
where tp_ListId like 'listid' and tp_level = 255

SharePoint 2010 Federated Search web part

Federated Search web part, Search Scope and Federated Location


  1. Create Search scope in Central Admin
    • Central Admin > Application Management > Manage Service Applications > Search Service Application > Scopes
    • New Scope
    • Set result page and rules to filter the search result, e.g. "YourUserProperty = 1", where YourUserProperty is a property or simply "contentclass = urn:content-class:SPSPeople"
  2. Create "Search Scopes" in Central Admin
    • Central Admin > Application Management > Manage Service Applications > Search Service Application > Manage Federated Locations
    • New Location
      • Set properties:
      • More Results Link Template: add an URL and a "*" after each search term when pressing the More Results link, e.g. "yourresultpage.aspx?k={searchTerms}*"
      • Query Template: add scope if preferred, e.g. {searchTerms} scope:YourScope
  3. Add "Federated Results" web part to the Site
    • Set "Federated Location" to a location created in Central Admin