How to Enable/Disable Numerous Features Across an Entire Farm

I was recently asked to enable and disable certain features across an entire farm that were activated by virtue of having upgraded to the SharePoint enterprise license.  The key is that to do this effectively, I wrote some PowerShell, and I needed the Feature ID.  The table of features with their IDs is below.

Short Name Feature ID
Deactivate (site collection features)    
Document ID Service Feature DocId b50e3104-6812-424f-a011-cc90e6327318
Disposition Approval Workflow feature ExpirationWorkflow c85e5759-f323-4efb-b548-443d2216efb5
In Place Records Management Feature InPlaceRecords da2e115b-07e4-49d9-bb2c-35e93bb9fca9
Library and Folder Based Retention Feature LocationBasedPolicy 063c26fa-3ccc-4180-8a84-b6f98e991df3
Deactivate (site features (i.e. web))    
Content Organizer DocumentRouting 7ad5272a-2694-4349-953e-ea5ef290e97c
E-mail Integration with Content Organizer EMailRouting d44a1358-e800-47e8-8180-adf2d0f77543
     
Activate (site collection feature)    
Open Documents in Client Applications by Default OpenInClient 8a4b8de2-6fd8-41e9-923c-c7c3c00f8295

 

The following is the PowerShell I used to enable / disable these features on the web application “webapplication.company.com”.  Note that if you wanted to do this across multiple web applications, you would need to do this block of statements for each web application in the farm.

Get-SPWebApplication http://webapplication.company.com | Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity “b50e3104-6812-424f-a011-cc90e6327318” -URL $_.URL -confirm:$false}
Get-SPWebApplication “
http://webapplication.company.com” | Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity “c85e5759-f323-4efb-b548-443d2216efb5” -URL $_.URL -confirm:$false}
Get-SPWebApplication “
http://webapplication.company.com” | Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity “da2e115b-07e4-49d9-bb2c-35e93bb9fca9” -URL $_.URL -confirm:$false}
Get-SPWebApplication “
http://webapplication.company.com” | Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity “063c26fa-3ccc-4180-8a84-b6f98e991df3” -URL $_.URL -confirm:$false}
Get-SPWebApplication “
http://webapplication.company.com” | Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity “7ad5272a-2694-4349-953e-ea5ef290e97c” -URL $_.URL -confirm:$false}
Get-SPWebApplication “
http://webapplication.company.com” | Get-SPSite -Limit ALL | ForEach-Object {Disable-SPFeature -identity “d44a1358-e800-47e8-8180-adf2d0f77543” -URL $_.URL -confirm:$false}
Get-SPWebApplication “
http://webapplication.company.com” | Get-SPSite -Limit ALL | ForEach-Object {Enable-SPFeature -identity “8a4b8de2-6fd8-41e9-923c-c7c3c00f8295” -Url $_.Url -confirm:$false}