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

[玩转系统] 查找 SharePoint 网站栏使用情况 - 报告

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

查找 SharePoint 网站栏使用情况 - 报告


当尝试删除 SharePoint 网站栏时,它向我发出警告,提示“无法删除内容类型中包含的网站栏。在删除此网站栏之前先删除对此网站栏的所有引用。”

[玩转系统] 查找 SharePoint 网站栏使用情况 - 报告

好吧,在删除特定网站栏之前,让我们使用 PowerShell 查找哪些列表或内容类型正在使用该网站栏。

用于从内容类型中查找并删除网站栏的 PowerShell 脚本


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web= Get-SPWeb "https://sharepoint.crescent.com/sites/operations"
$ColumnInternalName = "BranchLocation"

#Get All Content Types
$CTypes = $web.site.rootweb.ContentTypes
foreach($ContentType in $CTypes)
 {
  $FieldInUse = $ContentType.FieldLinks | Where {$_.Name -eq $ColumnInternalName }
 
   if($FieldInUse -ne $null) 
   {
            Write-Host "Found the Column in Content Type:" $ContentType.Name -ForegroundColor DarkGreen
            #To Remove the field from content type, uncomment below two lines
            #$ContentType.FieldLinks.Delete($ColumnInternalName)
            #$ContentType.Update()
    }
 }

完毕!再次尝试删除网站栏时,收到“此网站栏将被删除,并且从中创建的所有列表栏将被永久孤立。您确定要删除此网站栏吗?”

[玩转系统] 查找 SharePoint 网站栏使用情况 - 报告

嗯,这是什么意思?创建网站栏是为了最大限度地减少重复并提供一致性。因此,如果我们删除站点列,则创建的所有列表/库列将继续保留其值。不会对数据产生任何影响。但他们将成为当地的专栏。好吧,在删除网站栏之前,让我们看看它实际在哪里使用?让我们使用 PowerShell 在特定网站集中查找我们的网站栏的所有引用。

用于查找列表上网站列使用情况的 PowerShell 脚本


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site URL
$SiteURL = "https://sharepoint.crescent.com/sites/operations"
#Column to search
$ColumnInternalName = "BranchLocation"

#Get the Web
$Site = Get-SPSite $SiteURL
#Get the Column
$column = $site.RootWeb.Fields.GetFieldByInternalName($ColumnInternalName)

#Find all List usages of the column
$SiteColumnUsages = $column.ListsFieldUsedIn() #Gets the WebID & ListID values

#Get the lists where the site column is being used
foreach( $Usage in $SiteColumnUsages )
{
        $Site.AllWebs | foreach {$_.Lists} | where {$_.ID -eq $Usage.ListID } | Select Title, ParentWebURL, RootFolder
}
 
Write-Host "Checking Lists to Remove the Site column..."
foreach( $Usage in $SiteColumnUsages )
{
   #Remove columns from Lists where its used 
   $List =  $Site.AllWebs | foreach {$_.Lists} | where {$_.ID -eq $Usage.ListID } 
   if($List.Fields.ContainsFieldWithStaticName($ColumnInternalName))
   {
      $field = $List.Fields.GetFieldByInternalName($ColumnInternalName)

      ## Uncomment these four lines to actually delete a site column from Lists
      #$field.AllowDeletion = $true
      #$field.Update()
      #$List.Fields.GetFieldByInternalName($ColumnInternalName).Delete()
      #$List.Update()
      Write-Host "Site column $($ColumnInternalName) has been removed from $($List.RootFolder) at $($List.ParentWeb.URL)"
   }
} 

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

取消回复欢迎 发表评论:

关灯