Friday, January 22, 2016

PowerShell: Activate Nintex Workflow For a Site Collection (Includes all Sub Sites)

Recently I was on a project which was using Nintex Workflow 2013 and we needed to have the site collection feature activated, as well as the Nintex Workflow 2013 site feature on all of the sub sites within this particular site collection.  Well this was an intranet site which was comprised of 50 sub sites which would all need to be enabled.

In order to use Nintex Workflow the site collection feature must be activated as well as the site feature for any sub site which wishes to use the Workflow Product.  As much fun as manually clicking through 50+ sites and activating the feature would be, I found a script online and tweaked it a bit to be a bit more robust.  Original script author Vadim Tabakman wrote the bulk of the script, my additions are noted in the script comments.



Best Regards,
Dan


#Orignal Script Author: Vadim Tabakman
#http://www.vadimtabakman.com/nintex-workflow-enable-the-nintex-workflow-feature-on-all-subsites.aspx

#Updates By Dan Adams
    #Added a param for re-usablilty rather than have a set path
    #Added the logic to enable the Site Collection Nintex Workflow Feature before enabling the sites
    #Wrapped the Enable-SPFeature calls to handle errors if the Feature was already activated on the site

param($url = $(Read-Host -prompt "Root Site Collection Path"))

#Get the PowerShell Snapin
Add-PSSnapin "Microsoft.SharePoint.PowerShell"

#Get Web
$web = get-spweb $url
#Get Site
$rootSite = Get-SPSite $url

#Activate Site Collection Feature If Not Activated
$nintexWFCollectionFeature = "0561d315-d5db-4736-929e-26da142812c5"
(Enable-SPFeature -Identity $nintexWFCollectionFeature -ErrorAction SilentlyContinue -Url $url) -$null


#Loops Through the SubSites and Activates Nintex Workflow Web Feature
function EnableNintexWorkflowSiteFeature( $w )
{
    $ws = $w.Webs;
    foreach( $subweb in $ws)
    {
        EnableNintexWorkflowSiteFeature($subweb)
    }
    echo 'Enabling Nintex Workflow on site : ' $w.Url
    (Enable-SPFeature NintexWorkflowWeb -ErrorAction SilentlyContinue -url $w.Url) -ne $null
}

echo 'Enabling Nintex Workflow on site : ' + $web.Url
EnableNintexWorkflowSiteFeature $web

No comments:

Post a Comment