Powershell Script to Find SharePoint Web Scoped Features

  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm  
  2. $LogFile = ".\WebScopedFeaturePatch-$LogTime.rtf"  
  3.  
  4. # Add SharePoint PowerShell Snapin  
  5.   
  6.   
  7. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {  
  8.     Add-PSSnapin Microsoft.SharePoint.Powershell  
  9. }  
  10.   
  11. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent  
  12. Set-Location $scriptBase  
  13.  
  14.  
  15. #Deleting any .rtf files in the scriptbase location  
  16. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf  
  17. if($FindRTFFile)  
  18. {  
  19.   foreach($file in $FindRTFFile)  
  20.   {  
  21.    remove-item $file  
  22.   }  
  23. }  
  24.   
  25.   
  26. start-transcript $logfile  
  27.   
  28. try {  
  29.    Write-Verbose "Getting features at the Web Scope ..."  
  30.    $features = Get-SPFeature -Limit All | Where-Object {$_.Scope -eq "WEB"} | Sort-Object DisplayName  
  31.    Write-Output $features  
  32. }  
  33. catch [Exception] {  
  34.    Write-Error $Error[0]  
  35.    $err = $_.Exception  
  36.    while ( $err.InnerException ) {  
  37.       $err = $err.InnerException  
  38.       Write-Output $err.Message  
  39.    }  
  40. }