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

[玩转系统] 使用 PowerShell 在 SharePoint 中托管元数据列使用情况报告

作者:精品下载站 日期:2024-12-14 14:08:07 浏览:16 分类:玩电脑

使用 PowerShell 在 SharePoint 中托管元数据列使用情况报告


要求:查找 SharePoint 环境中所有托管元数据列的使用情况。

[玩转系统] 使用 PowerShell 在 SharePoint 中托管元数据列使用情况报告

PowerShell 查找托管元数据列的使用情况:

以下是用于查找 SharePoint 网站集中所有托管元数据列的 PowerShell 脚本。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$SiteCollURL="https://portal.crescent.com"
$ReportOutput="c:\MMS-Columns.csv"

$WebsColl = (Get-SPSite $SiteCollURL).AllWebs

#Array to hold Results
$ResultColl = @()

#Loop through each site, List and Fields
Foreach($web in $WebsColl)
    { 
        Write-host "Scanning Web:"$Web.URL
        Foreach($list in $web.Lists)            
        {
            Foreach($Field in $list.Fields)            
            {            
                if($field.GetType().Name -eq "TaxonomyField")
                {
                    $Result = New-Object PSObject
                    $Result | Add-Member -type NoteProperty -name "List Name" -value $List.Title
                    $Result | Add-Member -type NoteProperty -name "URL" -value "$($List.ParentWeb.Url)/$($List.RootFolder.Url)"
                    $Result | Add-Member -type NoteProperty -name "Field Name" -value $Field.Title
       
                    $ResultColl += $Result
                }
            }
        }
    }
#Export Results to a CSV File
$ResultColl | Export-csv $ReportOutput -notypeinformation
Write-Host "Managed Metadata columns usage Report has been Generated!" -f Green 

此脚本扫描给定网站集的每个列表并生成 CSV 格式的报告。

PowerShell 用于查找所有正在使用的托管元数据术语:

现在是下一部分。了解这些 MMS 列中使用了哪些术语?他们的价值观:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$SiteCollURL="https://portal.crescent.com"
$ReportOutput="c:\MMS-Terms-Usage.csv"

$WebsColl = (Get-SPSite $SiteCollURL).AllWebs

#Array to hold Results
$ResultColl = @()

#Loop through each site, List and Fields
Foreach($web in $WebsColl)
    { 
        Write-host "Scanning Web:"$Web.URL
        Foreach($list in $web.Lists)            
        {
            #Get all Managed metadata fields
            Foreach($Field in $list.Fields | where {$_.GetType().Name -eq "TaxonomyField"})
                {
                    Foreach ($item in $list.Items)
                    {
                        #Get All values of MMS field
                        $MMSFieldValueColl = $item[$Field.Title] #-as [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection]
                        
                        #concatenate each term in the collection
                        $MMSFieldTerms=[string]::Empty
                        Foreach ($MMSFieldValue in $MMSFieldValueColl)
                        {
                            if($MMSFieldValue.label -ne $null)
                            {
                                $MMSFieldTerms+=$MMSFieldValue.label+";"
                            }
                        }
                        
                        #Collect the result
                        if($MMSFieldTerms -ne '')
                        {
                            $Result = New-Object PSObject
                            $Result | Add-Member -type NoteProperty -name "MMs Column Name" -value $Field.Title
                            $Result | Add-Member -type NoteProperty -name "MMS Column Value" -value $MMSFieldTerms
                            #Get the URL of the Item
                            $ItemURL= $Item.ParentList.ParentWeb.Site.MakeFullUrl($item.ParentList.DefaultDisplayFormUrl)
                            $ItemURL=$ItemURL+"?ID=$($Item.ID)"
                            $Result | Add-Member -type NoteProperty -name "Item URL" -value $ItemURL
                            $Result | Add-Member -type NoteProperty -name "List Name" -value $List.Title
                            $Result | Add-Member -type NoteProperty -name "List URL" -value "$($List.ParentWeb.Url)/$($List.RootFolder.Url)"
       
                            $ResultColl += $Result
                        }
                    }
                }
        }
    }

#Export Results to a CSV File
$ResultColl | Export-csv $ReportOutput -notypeinformation
Write-Host "Managed Metadata columns usage Report has been Generated!" -f Green 

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

取消回复欢迎 发表评论:

关灯