Problem:
The department has a site collection that is heavily used and is a key site collection.The business would like to standardise site collection features across the board.
How to activate a standard list of features in all site collections for a web application using powershell script for SharePoint.
Solution:
Note: # is a comment in powershell
Contents of ManualListofFeaturesInEDSite.txt - This contains all the features that need to be activated. If you do not wish to read from a text file and use a reference site then just use
$allSiteColFeature = Get-SPFeature -site "http://muwebapp/sites/nintex" | Select displayname, id
NintexWorkflow
NintexWorkflowWebParts
NintexWorkflowInfoPath
NintexWorkflowEnterpriseWebParts
NintexWorkflowContentTypeUpgrade
OfficeWebApps
OpenInClient
ReviewPublishingSPD1033
ReportServer
Reporting
PublishingSite
BaseSite
InPlaceRecords
LocationBasedPolicy
WAReports
DocumentSet
DocId
Workflows
LocationBasedPolicy
ViewFormPagesLockDown
***** Script begins here ******
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\Admin\SiteFeaturesoutput.txt -append
$webs = get-spsite -webapplication "http://mywebapp" -Limit All
# Returns a detailed list of features, hence not being used
#$allSiteColFeature = Get-SPFeature -site "http://muwebapp/sites/nintex" | Select displayname, id
$fileContent = Get-Content "C:\drive\PROJECTS\DEVELOPMEN\ManualListofFeaturesInEDSite.txt"
#$oneweb = "http://mywebapp/sites/nintex"
Foreach ($oneweb in $webs)
{
Foreach ($featureId in $fileContent)
{
#$siteFeature = get-spfeature -site $oneweb | Where {$_.id -eq $featureId.id}
$siteFeature = get-spfeature -site $oneweb | Where {$_.displayname -eq $featureId.displayname}
if ($siteFeature -eq $null)
{
Write-Host "Activating Site level Features at $oneweb FeatureID: $featureid" -foregroundcolor Yellow
Enable-SPFeature $featureId -URL $oneweb.URL -Confirm:$False
#Disable-SPFeature $featureId -URL $oneweb.URL -Confirm:$False
#Enable-SPFeature $featureId -URL $oneweb -Confirm:$False
}
else
{
Write-Host "Feature $feature is already activated on $oneweb" -foregroundcolor green
}
}
}
Stop-Transcript
****** End of Script ******
The department has a site collection that is heavily used and is a key site collection.The business would like to standardise site collection features across the board.
How to activate a standard list of features in all site collections for a web application using powershell script for SharePoint.
Solution:
Note: # is a comment in powershell
Contents of ManualListofFeaturesInEDSite.txt - This contains all the features that need to be activated. If you do not wish to read from a text file and use a reference site then just use
$allSiteColFeature = Get-SPFeature -site "http://muwebapp/sites/nintex" | Select displayname, id
NintexWorkflow
NintexWorkflowWebParts
NintexWorkflowInfoPath
NintexWorkflowEnterpriseWebParts
NintexWorkflowContentTypeUpgrade
OfficeWebApps
OpenInClient
ReviewPublishingSPD1033
ReportServer
Reporting
PublishingSite
BaseSite
InPlaceRecords
LocationBasedPolicy
WAReports
DocumentSet
DocId
Workflows
LocationBasedPolicy
ViewFormPagesLockDown
***** Script begins here ******
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\Admin\SiteFeaturesoutput.txt -append
$webs = get-spsite -webapplication "http://mywebapp" -Limit All
# Returns a detailed list of features, hence not being used
#$allSiteColFeature = Get-SPFeature -site "http://muwebapp/sites/nintex" | Select displayname, id
$fileContent = Get-Content "C:\drive\PROJECTS\DEVELOPMEN\ManualListofFeaturesInEDSite.txt"
#$oneweb = "http://mywebapp/sites/nintex"
Foreach ($oneweb in $webs)
{
Foreach ($featureId in $fileContent)
{
#$siteFeature = get-spfeature -site $oneweb | Where {$_.id -eq $featureId.id}
$siteFeature = get-spfeature -site $oneweb | Where {$_.displayname -eq $featureId.displayname}
if ($siteFeature -eq $null)
{
Write-Host "Activating Site level Features at $oneweb FeatureID: $featureid" -foregroundcolor Yellow
Enable-SPFeature $featureId -URL $oneweb.URL -Confirm:$False
#Disable-SPFeature $featureId -URL $oneweb.URL -Confirm:$False
#Enable-SPFeature $featureId -URL $oneweb -Confirm:$False
}
else
{
Write-Host "Feature $feature is already activated on $oneweb" -foregroundcolor green
}
}
}
Stop-Transcript
****** End of Script ******
No comments:
Post a Comment