当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 的 SharePoint 功能使用情况报告

作者:精品下载站 日期:2024-12-14 13:44:19 浏览:12 分类:玩电脑

使用 PowerShell 的 SharePoint 功能使用情况报告


任务:为整个 SharePoint 环境的所有已安装/激活的功能生成报告。以下是一些漂亮的 PowerShell 脚本,用于查找场上安装的功能以及在特定范围内激活的特定功能。

Get-SPFeature cmdlet:
当未提供“Scope”参数值时,Get-SPFeature cmdlet 会检索环境中安装的所有功能。当您提供范围参数时,它会获取特定范围内的所有激活的功能:(例如:-site“https://sharepointsite.com”)

获取所有已安装的 SharePoint 功能的列表(按功能范围分组):


Get-SPFeature | Sort-Object Scope | Format-Table -GroupBy scope

[玩转系统] 使用 PowerShell 的 SharePoint 功能使用情况报告

让我们导出到文本文件:


Get-SPFeature | Sort -Property Scope, DisplayName | Ft -Autosize -GroupBy Scope DisplayName, Id > D:\FeaturesReport.txt

要在特定 Web 应用程序范围内激活所有功能,请使用:


Get-SPFeature -WebApplication "web-app-url"
#Similarly:
#Get-SPFeature -Farm
#Get-SPFeature -Site $Site.URL
#Get-SPFeature -Web $web.URL

获取所有功能及其标题:


Get-SPFeature | Format-Table @{Label='ID';Expression={$_.Id}}, 
@{Label='DisplayName';Expression={$_.DisplayName}}, 
@{Label='Title';Expression={$_.GetTitle(1033)}}, 
@{Label='Scope';Expression={$_.Scope}} -AutoSize | Out-File -Width 250 
D:\AllFeatures.txt

获取在特定网站集上激活的所有功能图块和描述:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$siteurl = "https://sharepoint.crescent.com"

Get-SPFeature -Limit ALL -Site $siteurl | ForEach-Object {
  $data = @{ 
  Feature = $_.GetTitle(1033)
  Description = $_.GetDescription(1033)
 }
 New-Object PSObject -Property $data; 
} | Select-Object Feature, Description 

查找 SharePoint 2013/SharePoint 2010 中的所有/特定功能:
让我们查找并列出激活功能的位置。


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$FeatureName = "TemplateDiscovery"
#We can also use "FeatureID" instead of Feature DisplayName 

# Get all Farm scoped features
#write-host "Farm scoped features:"
#Get-SPFeature -Farm 

# To Search for a specific Farm scoped feature:
Get-SPFeature -Farm | where { $_.DisplayName -eq $FeatureName } #Eg SpellChecking

 #Process All Web Applications
 ForEach ($WebApp in Get-SPWebApplication)
 {
    write-host "`nProcessing Web Application:" $webapp.url  
    #Get All Web Application Scoped features 
    #Get-SPFeature -WebApplication $WebApp.url 

    # To Search for a specific WebApplication scoped feature:
    Get-SPFeature -WebApplication $WebApp.url | where { $_.DisplayName -eq $FeatureName }

    #Process each site collection
    foreach ($site in $WebApp.sites) 
    {
      write-host "`tProcessing Site Collection: " $site.url 
      #Get All Site collection Scoped features 
      #Get-SPFeature -Site $site.url 

      # To Search for a specific Site Collection scoped feature:
      Get-SPFeature -Site $site.url | where { $_.DisplayName -eq $FeatureName }

      #Process each site
      foreach ($web in $site.AllWebs) 
      {
         write-host "`t`tProcessing Web: " $web.url 
         # Get All Web scoped features
         #Get-SPFeature -Web $web 

         # To Search for a specific Site Collection scoped feature:
         Get-SPFeature -Web $web | where { $_.DisplayName -eq $FeatureName }
       }
    }
 }

使用 STSADM 的 SharePoint 2007 功能清单:
Stsadm -o enumallwebs -includefeature

使用 PowerShell 查找 MOSS 2007 中的所有功能:
此脚本获取 Web 应用程序、网站集、网站范围内所有激活的功能:


[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Function global:Get-SPWebApplication($WebAppURL)
{
 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}

  #Get the SharePoint Farm. Equallent to : Get-SPFarm commandlet
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

  #Get All feature of the farm. Equallent to: Get-SPFeature commandlet
  $FarmFeatures= $Farm.FeatureDefinitions
  
  $WebAppURL = "https://SharePoint.Crescent.com"
  $WebApp = Get-SPWebApplication $WebAppURL
  
   #Scan Web Application Features
    Write-Host  "Features Activated at Web Application Level:"  -ForegroundColor DarkGreen

   foreach($feature in $WebApp.Features)
   {
      #Write-Host $feature.DefinitionId;
      Write-Host $farmfeatures[$feature.DefinitionId].DisplayName 
   }
  
  #Get All site collections of the Web Application  
  $SitesColl = $webApp.Sites  
  
  #Iterate through each site collection/sub-site
  foreach($Site in $SitesColl)
  {
   Write-Host "`nFeatures Activated at SITE:" $site.Url -ForegroundColor DarkGreen

   #Iterate through each feature activated at Site collection level
   foreach($feature in $site.Features)
   {
      #Write-Host $feature.DefinitionId;
      Write-Output $farmfeatures[$feature.DefinitionId].DisplayName;
   }
    foreach($web in $site.AllWebs)
    {
       Write-Host "`nFeatures Activated at WEB:" $web.Url -ForegroundColor DarkGreen
       #Iterate through each feature activated at web level
       foreach($Feature in $web.Features)
       {
          Write-Output $FarmFeatures[$Feature.DefinitionId].DisplayName;
          #Write-Output $FarmFeatures[$Feature.DefinitionId].GetTitle(1033);
       }
    }
  }

适用于 SharePoint 2007 的 Get-SPFeature Cmdlet:
用于报告所有 SharePoint 场功能的 Powershell 脚本


[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Get the SharePoint Farm. Equallent to : Get-SPFarm commandlet
$Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

#Get All feature of the farm. Equallent to: Get-SPFeature commandlet
$FarmFeatures= $Farm.FeatureDefinitions
$FarmFeatures | Select ID,DisplayName, Scope | Sort-Object Scope | Format-Table -GroupBy Scope
提示:要了解所有 SharePoint 企业功能的使用情况,请在功能显示名称上相应地使用:PremiumWebApplication、PremiumSite、PremiumWeb。

查找 SharePoint 2007 中特定功能的使用情况:


#Get-SPWebApplication Cmdlet for MOSS 2007
Function global:Get-SPWebApplication($WebAppURL)
{  
   if($WebAppURL -eq $null)  #Get All Web Applications
    {
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
    $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
    $WebApps = @()
    foreach ($websvc in $websvcs) 
  {
      foreach ($WebApp in $websvc.WebApplications) 
   {
          $WebApps += $WebApp
      }
  }
   return $WebApps
  }
 else #Get Web Application for given URL
 {
  return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
 }
}

  #Get the SharePoint Farm. Equallent to : Get-SPFarm commandlet
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

  #Get All feature of the farm. Equallent to: Get-SPFeature commandlet
  $FarmFeatures= $Farm.FeatureDefinitions
  
  #Feature to Search
  $FeatureDisplayName = "IPFSWebFeatures" #Infopath Form Services Feature
  
  #Scan Farm Level Features
  $FarmLevelFeatures = $farm.FeatureDefinitions | Where-Object { ($_.Scope -eq "Farm") -and ($_.DisplayName -eq $FeatureDisplayName) }
  if($FarmLevelFeatures -ne $null)
  {
   "$($FeatureDisplayName) Installed at Farm Level!"
  }
   
   #Get all web applications and scan through 
   $WebApplications = Get-SPWebApplication "https://sharepoint.crescent.com"
   #To process all web applications, simply use: $WebApplications = Get-SPWebApplication 
   foreach($WebApp in $WebApplications)
   {
  Write-Host "Processing web Application : $($WebApp.url)"
  $WebAppLevelFeature = $webApp.Features |  Where-Object { $_.Definition.DisplayName -eq $FeatureDisplayName }
  #If Feature found
  if($WebAppLevelFeature -ne $null)
  {
  "$($FeatureDisplayName) Activated at Web Application $($webApp.URL)"
  }
    
  #Get All site collections of the Web Application  
  $SitesColl = $webApp.Sites  
  
  #Iterate through each site collection
  foreach($Site in $SitesColl)
  {
      #Write-host "Processing Site: $($Site.Url)"
   $SiteLevelFeature = $Site.Features |  Where-Object { $_.Definition.DisplayName -eq $FeatureDisplayName     }
   #If Feature found
   if($SiteLevelFeature -ne $null)
     {
    "$($FeatureDisplayName) Activated at Site Collection $($Site.URL)"
     }
    
    #Enumerate each sub-site
    foreach($web in $site.AllWebs)
    {
         #Write-host "Processing Web: $($Web.Url)"
         $WebLevelFeature = $web.Features | Where-Object { $_.Definition.DisplayName -eq $FeatureDisplayName }
    #If Feature found
     if($WebLevelFeature -ne $null)
        {
          "$($FeatureDisplayName) Activated at Web Level $($web.URL)"
        }
     $web.Dispose()
  }
   $site.Dispose()
  }
}

如何找到所有自定义功能?
我们可以在新的共享点计算机上运行 Get-SPFeature,将该清单保存在 csv 文件中。
在具有自定义功能的目标机器中再次运行它并进行比较!

最近,在Technet论坛上发现了这个脚本:


Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

$siteurl = "https://sharepoint.crescent.com"
$Site = Get-SPSite $siteURL

#send all features to output file features.txt
$site.WebApplication.Farm.FeatureDefinitions `
| where-object {$_.solutionid -ne '00000000-0000-0000-0000-000000000000'} `
| Sort-Object solutionid,displayname `
| ft -property displayname,scope -auto -groupBy solutionid > "d:\features.txt"

#replace solutionId in features.txt with solution name
foreach($solution in $site.WebApplication.Farm.Solutions)
{
    (Get-Content "d:\features.txt") `
    | Foreach-Object {$_ -replace $solution.solutionid.ToString(), $solution.Name} `
    | Set-Content "D:\features.txt"
}

$site.Dispose()

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯