Saturday, July 30, 2011

PowerShell to help with Branding Deployment

Whilst working on a project to deploy a new branding solution, there was a requirement to disable existing brand features on all webs and site collections across all web applications, and then deploy a new branding solution to all root webs on all site collections. To do this manually would have been very tedious and time consuming, so using some simple PowerShell scripts made this process very easy and fast. Here are the scripts used:

DisableFeatures

$webApp = "http://WebAppUrl/"
$StapleFeature = Get-SPFeature | where {$_.DisplayName -eq "Name"}
$BrandingFeature = Get-SPFeature | where {$_.DisplayName -eq "Name"}
$WebPartsFeature = Get-SPFeature | where {$_.DisplayName -eq "Name"}

# Site collection scoped features
# Get all sites in the web app and if the feature exists, disable it
Get-SPSite -WebApp $webApp | foreach {
if($_.Features[$StapleFeature.ID]) {
Disable-SPFeature $StapleFeature -url $_.URL -Force -Confirm:$false
Disable-SPFeature $WebPartsFeature -url $_.URL -Force -Confirm:$false
}
}

# Web scoped features
# Get all webs in all sites in the web app and if the feature exists, disable it
Get-SPSite -WebApp $webApp | Get-SPWeb -limit all | foreach {
if($_.Features[$BrandingFeature.ID]) {
Disable-SPFeature $BrandingFeature -url $_.URL -Force -Confirm:$false
}
}

Enable Features

$webApp = "http://WebAppUrl/"
$StapleFeature = Get-SPFeature | where {$_.DisplayName -eq "Name"}
$BrandingFeature = Get-SPFeature | where {$_.DisplayName -eq "Name"}
$WebPartsFeature = Get-SPFeature | where {$_.DisplayName -eq "Name"}

# Site collection scoped features
# Enable features in all sites in the web app
Get-SPSite -WebApp $webApp | foreach {
Enable-SPFeature $StapleFeature -url $_.Url -Force
Enable-SPFeature $BrandingFeature -url $_.Url -Force
Enable-SPFeature $WebPartsFeature -url $_.Url -Force
}

I only had a couple of web apps, so just replaced the web app URL $webApp for each one and ran the scripts. You could just put another foreach and loop through all the webs if needed.

No comments:

Post a Comment