0

We are starting to use managed metadata all across our tenant and I would like to know when a Project number is used in a site collection. Is there a Powershell available that will tell the admin all sites that are using a particular termset is being referenced?

  • Do you want the name and id of the content types that uses this site column, or is it the url of the lists you need? – Kasper Bo Larsen Aug 25 at 7:20
  • The list Urls ideally – Michael Colbs Aug 26 at 16:32
1

this one will, using brute force id where that term set is used

$cred = Get-Credential

$AdminSite = "https://YOURTENANT-admin.sharepoint.com"
$TermSetID = "GUID OF THE TERM SET " #"e9a61c88-b243-4cd2-8f82-fc55cb8b3fb9"

Connect-PnPOnline -Url $AdminSite -Credentials $cred
$siteCollections  = Get-PnPTenantSite

foreach( $sitecollection in $siteCollections)
{
    Connect-PnPOnline -Url $sitecollection.Url -Credentials $cred
    $ctx = Get-PnPContext

    $lists = get-pnpList
    foreach ($list in $lists)
    {
        #write-host $list.Title -ForegroundColor Blue
        $columns = Get-PnPField -List $list 

        foreach($column in $columns)
        {
            #Write-Host $column.TypeDisplayName -ForegroundColor Green
            if($column.TypeDisplayName -eq "Managed Metadata") 
            {
                #Write-Host $column.TermGuid -ForegroundColor White
                if( $column.TermSetId -eq $TermSetID)
                {
                    Write-Host "Column " $TermSetID " found at " $list.Title ", URL:" $list.ParentWebUrl -ForegroundColor Red
                }
            }
        }
    }


    $subwebs = get-pnpsubwebs -Web $ctx.Web

    foreach($subweb in $subwebs)
    {
        write-host $subweb.Title

        $lists = get-pnpList -Web $subweb
        foreach ($list in $lists)
        {
            $columns = Get-PnPField -List $list.Title 

            foreach($column in $columns)
            {
                #Write-Host $column.InternalName -ForegroundColor Green
                #Write-Host $column.TypeDisplayName -ForegroundColor Green
                if($column.TypeDisplayName -eq "Managed Metadata") 
                {
                    #Write-Host $column.TermGuid -ForegroundColor White
                    if( $column.TermGuid -eq $TermSetID)
                    {
                        Write-Host "Column " $TermSetID " found at " $list.Title ", URL:" $list.ParentWebUrl -ForegroundColor Red
                    }
                }
            }

        }
    }
}
1

Uos, sorry, picked the wrong file, this is the right one

$spSiteCollection = "https://YOURTENANT.sharepoint.com/sites/YOURSITE"
$SiteColumnName = "COLUMNINTERNALNAME"

Connect-PnPOnline -Url $spSiteCollection 
$ctx = Get-PnPContext

$lists = get-pnpList
    foreach ($list in $lists)
    {
        #write-host $list.Title -ForegroundColor Blue
        $columns = Get-PnPField -List $list 

        foreach($column in $columns)
        {
            #Write-Host $column.InternalName -ForegroundColor Green
            if( $column.InternalName -eq $SiteColumnName)
            {
                Write-Host "Column " $SiteColumnName " found at " $list.Title ", URL:" $list.ParentWebUrl -ForegroundColor Red
            }
        }

    }

$subwebs = get-pnpsubwebs -Web $ctx.Web

foreach($subweb in $subwebs)
{
    write-host $subweb.Title
    $lists = get-pnpList -Web $subweb
    foreach ($list in $lists)
    {
        write-host $list.Title -ForegroundColor Blue
        $columns = Get-PnPField -List $list -Web $subweb

        foreach($column in $columns)
        {
            #Write-Host $column.InternalName -ForegroundColor Green
            if( $column.InternalName -eq $SiteColumnName)
            {
                Write-Host "Column " $SiteColumnName " found at " $list.Title ", URL:" $list.ParentWebUrl -ForegroundColor Red
            }
        }

    }
}
  • Thanks, not bad but it doesn't loop through all sites in the tenant. Also, hard coding the internal column name doesn't guarantee it will match the global metadata field that I'm looking for – Michael Colbs Aug 30 at 16:05
  • Ok, now I understand what you are looking for : everywhere a specific term set is used? – Kasper Bo Larsen Aug 30 at 16:10
  • exactly @kasper – Michael Colbs Aug 30 at 16:31
0

Something like this should work:

$spSiteCollection = "https://YOURTENANT.sharepoint.com/sites/YOURSITE"
$ContentTypeName = "CONTENTTYPENAME"

Connect-PnPOnline -Url $spSiteCollection 
$ctx = Get-PnPContext

$lists = get-pnpList
    foreach ($list in $lists)
    {
        write-host $list.Title -ForegroundColor Blue
        $cts = Get-PnPContentType -List $list

        foreach($ct in $cts)
        {
            Write-Host $ct.Name -ForegroundColor Green
            if( $ct.Name -eq $ContentTypeName)
            {
                Write-Host "Content type " $ContentTypeName " found at " $list.Title ", URL:" $list.ParentWeb.Url -ForegroundColor Red
            }
        }

    }

$subwebs = get-pnpsubwebs -Web $ctx.Web

foreach($subweb in $subwebs)
{
    write-host $subweb.Title
    $lists = get-pnpList
    foreach ($list in $lists)
    {
        write-host $list.Title -ForegroundColor Blue
        $cts = Get-PnPContentType -List $list
        foreach($ct in $cts)
        {
            Write-Host $ct.Name -ForegroundColor Green
            if( $ct.Name -eq $ContentTypeName)
            {
                Write-Host "Content type " $ContentTypeName " found at " $list.Title ", URL:" $list.ParentWeb.Url -ForegroundColor Red
            }
        }

    }
}
  • This script seems to be searching a specific site collection for a specific content type. I'm looking to search all sites for a specific metadata field. – Michael Colbs Aug 28 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.