Thursday, February 28, 2013

BlobCache Script


Hi,

In SharePoint 2010,we have facility to manage the SharePoint Cache through BlobCache script.

So I am posting the Blob Cache script as below

# Enable-SPBlobCache Function
function Enable-SPBlobCache {
param(
                [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
                [Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]
                $WebApplication,
                [Parameter(Mandatory=$false, ValueFromPipeline=$true, Position=1)]
                $BlobCacheLocation="E:\BlobCache"
)

process {
    $WebApp = $WebApplication.Read()
    # SPWebConfigModification to enable BlobCache
    $configMod1 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
    $configMod1.Path = "configuration/SharePoint/BlobCache"
    $configMod1.Name = "enabled"
    $configMod1.Sequence = 0
    $configMod1.Owner = "BlobCacheMod"
    ## SPWebConfigModificationType.EnsureChildNode -> 0
    ## SPWebConfigModificationType.EnsureAttribute -> 1
    ## SPWebConfigModificationType.EnsureSection -> 2
    $configMod1.Type = 1
    $configMod1.Value = "true"
                                
    ######################################################################
               
                # SPWebConfigModification to enable client-side Blob caching (max-age)
    $configMod2 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
    $configMod2.Path = "configuration/SharePoint/BlobCache"
    $configMod2.Name = "max-age"
    $configMod2.Sequence = 0
    $configMod2.Owner = "BlobCacheMod"
    ## SPWebConfigModificationType.EnsureChildNode -> 0
    ## SPWebConfigModificationType.EnsureAttribute -> 1
    ## SPWebConfigModificationType.EnsureSection -> 2
    $configMod2.Type = 1
    $configMod2.Value = "86400"
               
                ######################################################################
               
                # SPWebConfigModification to change the default location for the Blob Cache files
                $configMod3 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
                $configMod3.Path = "configuration/SharePoint/BlobCache"
                $configMod3.Name = "location"
                $configMod3.Sequence = "0"
                $configMod3.Owner = "BlobCacheMod"
                ## SPWebConfigModificationType.EnsureChildNode -> 0
    ## SPWebConfigModificationType.EnsureAttribute -> 1
    ## SPWebConfigModificationType.EnsureSection -> 2
                $configMod3.Type = 1
                $configMod3.Value = $BlobCacheLocation
    # Add mods, update, and apply
    $WebApp.WebConfigModifications.Add( $configMod1 )
    $WebApp.WebConfigModifications.Add( $configMod2 )
                $WebApp.WebConfigModifications.Add( $configMod3 )
    $WebApp.Update()
    $WebApp.Parent.ApplyWebConfigModifications()
}
}

No comments:

Post a Comment