How To Generate An Object Cache User Account Report using PowerShell

This blog post describes how to generate a report of all Object Cache User Accounts for all web applications using PowerShell.  The sample script I’m providing accepts only one parameter, which defines the logging directory for the Object Cache Report

Background

Recently, I received a comment from one of my blog followers asking me if I could upload a script that would allow them to save their object cache accounts.  There are several ways to do this – for now I’m simply providing a script to produce a report.  I’m still planning to put up a script which would allow administrators to run the Move-SPUser cmdlet against every user in the environment without losing the object cache accounts.  That script is currently giving me some grief when there are two or more web applications present in the environment.

Approach

The approach in this case is very simple.  Get a list of all web applications, loop through each web application, return the object cache user accounts and log them to a file.

Solution

The solution in this case isn’t much more difficult than the approach.  The relevant portion of the script is as follows:

$WebApplications = Get-SPWebApplication
foreach ($WebApplication in $WebApplications)
{
$WebApplication.DisplayName
$WebApplication.url
$WebApplication.Properties["PortalSuperReaderAccount"]
$WebApplication.Properties["PortalSuperUserAccount"]
}

But of course, the rest of the script allows us to perform things like error handling, outputting the results to a file instead of the console, etc.

You can download the Object Cache User Account Report script from this location: Download ObjectCacheReport.ps1 (zipped)

Usage

Simply edit the script to include your desired Logging Directory and execute the script on your SharePoint server.

Feedback

As always, if you have any questions or feedback, let me know. If you have any ideas to optimize the script, I'd like to hear that too. Thanks for reading!