| 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070
| function Get-SPFeatureActivated { # see full script for help info, removed for formatting [CmdletBinding()] param( [Parameter(position = 1, valueFromPipeline=$true)] [string] $Identity )#end param Begin { # load SharePoint assembly to access object model [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") # declare empty array to hold results. Will add custom member for Url to show where activated at on objects returned from Get-SPFeature. $results = @() $params = @{} } Process { if([string]::IsNullOrEmpty($Identity) -eq $false) { $params = @{Identity = $Identity} } # create hashtable of farm features to lookup definition ids later $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local # check farm features $results += ($farm.FeatureDefinitions | Where-Object {$_.Scope -eq "Farm"} | Where-Object {[string]::IsNullOrEmpty($Identity) -or ($_.DisplayName -eq $Identity)} | % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value ([string]::Empty) -PassThru} | Select-Object -Property Scope, DisplayName, Id, Url) # check web application features $contentWebAppServices = $farm.services | ? {$_.typename -like "Windows SharePoint Services Web Application"} foreach($webApp in $contentWebAppServices.WebApplications) { $results += ($webApp.Features | Select-Object -ExpandProperty Definition | Where-Object {[string]::IsNullOrEmpty($Identity) -or ($_.DisplayName -eq $Identity)} | % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $webApp.GetResponseUri(0).AbsoluteUri -PassThru} | Select-Object -Property Scope, DisplayName, Id, Url) # check site collection features in current web app foreach($site in ($webApp.Sites)) { $results += ($site.Features | Select-Object -ExpandProperty Definition | Where-Object {[string]::IsNullOrEmpty($Identity) -or ($_.DisplayName -eq $Identity)} | % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $site.Url -PassThru} | Select-Object -Property Scope, DisplayName, Id, Url) # check site features in current site collection foreach($web in ($site.AllWebs)) { $results += ($web.Features | Select-Object -ExpandProperty Definition | Where-Object {[string]::IsNullOrEmpty($Identity) -or ($_.DisplayName -eq $Identity)} | % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $web.Url -PassThru} | Select-Object -Property Scope, DisplayName, Id, Url) $web.Dispose() } $site.Dispose() } } } End { $results } } #end Get-SPFeatureActivated Get-SPFeatureActivated |