Managed Metadata Columns Usage Report in SharePoint using PowerShell
Requirement: Find the usage of all Managed Metadata columns in SharePoint environment.
PowerShell script to find managed metadata column usage:
Here is the PowerShell script to find all managed metadata columns in SharePoint site collection.
PowerShell script to find All Managed Metadata Terms in use:
Now the next part. Get what terms are being used in these MMS columns? Their values:
PowerShell script to find managed metadata column usage:
Here is the PowerShell script to find all managed metadata columns in SharePoint site collection.
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 GreenThis script scans each and every list of given site collection and generates report in CSV.
PowerShell script to find All Managed Metadata Terms in use:
Now the next part. Get what terms are being used in these MMS columns? Their values:
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="" 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
No comments:
Please Login and comment to get your questions answered!