Вопрос

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?

Это было полезно?

Решение

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
                    }
                }
            }

        }
    }
}

Другие советы

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
            }
        }

    }
}

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
            }
        }

    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top