Thursday, October 1, 2015

Listing All SharePoint Server Features of Web Application dynamic by power shell

Listing All SharePoint Server Features of Web Application dynamic by power shell
1. Writing the function to export all features of web application with parameter
function Get-SPFeatureActivated
{
[CmdletBinding()]
param(
    [parameter(Mandatory=$true)][string]$Url,#Input your URL of web application
    [parameter(Mandatory=$true)][string]$Path,#Input your file name which you want to export like (c:\features.csv)
    [Parameter(position = 1, valueFromPipeline=$true)]#Default para
    [Microsoft.SharePoint.PowerShell.SPFeatureDefinitionPipeBind]   
    $Identity
)#end param
    Begin
    {       
        $results = @()
       
        $params = @{}
    }
    Process
    {
        if([string]::IsNullOrEmpty($Identity) -eq $false)
        {
            $params = @{Identity = $Identity
                        ErrorAction = "SilentlyContinue"
            }
        }   

        # Get web application URL
    $webApplication = Get-SPWebApplication -Identity $Url
        foreach($webApp in $webApplication)
        {
            $results += (Get-SPFeature -WebApplication $webApp -Limit All @params |
                             % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $webApp.Url -PassThru} |
                             Select-Object -Property Scope, DisplayName, Id, Url)

            # check site collection features in current web app
            foreach($site in ($webApp.Sites))
            {
                $results += (Get-SPFeature -Site $site -Limit All @params |
                                 % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $site.Url -PassThru} |
                                 Select-Object -Property Scope, DisplayName, Id, Url)
                                
                $site.Dispose()

                # check site features in current site collection
                foreach($web in ($site.AllWebs))
                {
                    $results += (Get-SPFeature -Web $web -Limit All @params |
                                     % {Add-Member -InputObject $_ -MemberType noteproperty -Name Url -Value $web.Url -PassThru} |
                                     Select-Object -Property Scope, DisplayName, Id, Url)

                    $web.Dispose()
                }
            }
        }
    }
    End
    {
        $results > $Path
    }
}

2. Call function then input the value via parameter in above function

3. The result is all features is exported to csv file 
 Thanks.

0 comments:

Post a Comment