Get list of used managed metadata columns in a site collection

DWTK 61 Reputation points
2021-12-12T23:43:17.54+00:00

Hello,

I was wondering if there is a way to get a list of used managed metadata columns. I have tried using powershell script below in the SharePoint Online Management Shell;

$SiteCollURL="https://Mysite.sharepoint.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

However when I run the script I get the following error;

Get-SPSite : The term 'Get-SPSite' is not recognized as the name of a cmdlet, function, script file, or operable

program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:4 char:14

  • $WebsColl = (Get-SPSite $SiteCollURL).AllWebs
  • ~~~~~~~~~~
    • CategoryInfo : ObjectNotFound: (Get-SPSite:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

So after some searches, Apparently I have to add the following line:

Add-PSSnap in Microsoft.SharePoint.Powershell

but when I run it, I get the following message: Add-PSSnapin: No snap-ins have been registered for Windows PowerShell version 5

Any idea of what I'm doing wrong?

Any help would be much appreciated

Reply

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. DWTK 61 Reputation points
    2022-01-03T23:21:16.433+00:00

    @JulieWang-MSFT I figured out why the export results wasn't producing anything. I was under the assumption the solution you provided would scan through all the sites within the tenant. It does not, once I started using specific site collection URLs I was getting scan results. I thank you again for all your help. Now to copy and paste 1100+ URLs :)

    Happy new year,
    DWTK

    Was this answer helpful?


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    2 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.