Tag Archives: CACHE

Check Blob Cache settings across a farm

A routine but really annoying task came up today. The status of BLOB caching for all Web Applications, normally I’d hop into the config files and check but these are spread over 6 farms.
To make things worse each farm had between 4 and 5 web apps and between 1 and 3 WFEs. In total that should have meant checking in the region of 50 config files.

Sod that.

Getting data from the config file is easy, after all it’s just an xml document. Once we’ve got the document it’s a nice easy task to suck the actual values out:

	$xml = [xml](Get-Content $webConfig)
           $blobNode =  $xml.configuration.SharePoint.BlobCache
           $props = @{
                'Location' = $blobNode.location;
                'MaxSize' = $blobNode.maxsize;
                'Enabled' = $blobNode.enabled
           New-Object -TypeName PSObject -Property $props
That on it's own isn't that helpful. After all we don't just want to get the values for ONE config file, we want to get them for something like 50. Also I don't really want to have to list each one out, I just want them all... Through some rather excessive PowerShelling I know that we can get the config file's physical path from the IIS settings on a web application:
$WebApp = Get-SPWebApplication "http://sharepoint.domain.com" 
#This is horrible code but I haven't found a better way to get the value in a usable format.
$physicalPath = ($settings.Values | select path -Expand Path).Tostring()

That will give us the physical path to the folder containing the web.config file. It's only a small leap to make it loop through all the locations…

#Script to check the blob caching configuration in all webconfig files in your farm on all servers.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea SilentlyContinue

$outputFile = "C:\Folder\TestFile.txt"

#This is a rubbish way of getting the server names where the foundation web app is running but i can't
#find a better one at the moment.
$serversWithFWA =Get-SPServiceInstance `
    | ? { $_.TypeName-eq "Microsoft SharePoint Foundation Web Application" -AND $_.Status -eq "Online"} `
    | Select Server -ExpandProperty Server | select Address

Get-SPWebApplication | %{
    $configResults = @()
	$webAppName = $_.name
    Write-Host "Webapp $webAppName"
    #Get the physical path from the iis settings
    $settings =$_.IISSettings
    $physicalPath = ($settings.Values | select path -Expand Path).Tostring()
    #foreach server running the Foundation Web Application.
    foreach ($server in $serversWithFWA)
        #Build the UNC path to the file Note that this relies on knowing more or less where your config files are
        #This could be improved using regex.
        $serverUNCPath = $physicalPath.Replace("C:\",("\\" + $server.Address + "\C$\"))
        $webConfig = $serverUNCPath +"\web.config"
        #If the file exists then try to read the values
        If(Test-Path ($webConfig))
            $xml = [xml](Get-Content $webConfig)
            $blobNode =$xml.configuration.SharePoint.BlobCache

            $props = @{
				'Server' = $server.Address;
                'Location' = $blobNode.location;
                'MaxSize' = $blobNode.maxsize;
                'Enabled' = $blobNode.enabled
            $configResults += New-Object -TypeName PSObject -Property $props
	#Print the results out for the GUI
    $configResults | ft
	#Output the data into a useful format - start by printing out the file name
	$webAppName >>  $outputFile
	#CSV because the data is immeasurably easier to load into a table etc. later. HTML would be a good alternative
	$configResults | ConvertTo-CSV >> $outputFile