I am working on an installation of SharePoint 2010 For Internet Sites for my present client, and I’m automating almost everything using PowerShell cmdlets, scripts and advanced functions.
Thanks to this post, I was able to adapt with VERY little work to my needs. Really the only thing I needed that wasn’t provided in this set of functions was the ability to use a different location (not the default C:\BlobCache\14).
It was very easy to add another $configMod section ($configMod3) to do this, here’s the additional code I added:
I also added a parameter for $BlobCacheLocation, so you can provide the WebApplication and BlobCacheLocation values from the pipeline.
Easy, efficient and clean!
Here’s the code I added:
$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
$WebApp.WebConfigModifications.Add( $configMod3 )
Here’s the entire set of functions:
# 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="C:\BlobCache\14"
)
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()
}
}
# Disable-SPBlobCache Function
function Disable-SPBlobCache {
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]
$WebApplication
)
process {
$WebApp = $WebApplication.Read()
$mods = @()
foreach ( $mod in $WebApp.WebConfigModifications ) {
if ( $mod.Owner -eq "BlobCacheMod" ) {
$mods += $mod
}
}
foreach ( $mod in $mods ) {
[void] $WebApp.WebConfigModifications.Remove( $mod )
}
$WebApp.Update()
$WebApp.Parent.ApplyWebConfigModifications()
}
}
Like this:
Like Loading...