4

I am iterating through managed metadata using CSOM and PowerShell against SharePoint Online. I need to know if a managed metadata group is a site collection group or if it is global. When I use the following script to make that determination, it always responds with IsSiteCollectionGroup is false even though I know one of my groups is a site collection group. Am I missing something?

Add-Type -Path C:\SPClientLib\Microsoft.SharePoint.Client.dll
Add-Type -Path C:\SPClientLib\Microsoft.SharePoint.Client.Runtime.dll
Add-Type -Path C:\SPClientLib\Microsoft.SharePoint.Client.Taxonomy.dll

$url = Read-Host -Prompt "SPO Url"
$user = Read-Host -Prompt "user"
$pwd = Read-Host -Prompt "pwd" -AsSecureString
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$pwd)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$ctx.Credentials = $creds

$mms = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
$ctx.Load($mms)
$ctx.ExecuteQuery()
$termstores = $mms.TermStores
$ctx.Load($termstores)
$ctx.ExecuteQuery()

$termstore = $termstores[0]
$ctx.Load($termstore)

$groups = $termstore.Groups
$ctx.Load($groups)
$ctx.ExecuteQuery()

foreach ($group in $groups)
{
    $ctx.Load($group)
    $ctx.ExecuteQuery()
    #$ctx.Load($group.IsSiteCollectionGroup) # tried loading IsSiteCollectionGroup explicitly, but that gives an error
    #$ctx.ExecuteQuery()
    Write-Host "Group Name:" $group.Name "(site collection group? $($group.IsSiteCollectionGroup))"
}
1

The following script works for me, but it is pretty similar to your version:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Taxonomy")


Function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
{
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context
}



$UserName = "jdoe@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.sharepoint.com/"


$ctx = Get-SPOContext -Url $Url -UserName $UserName -Password $Password
$taxSession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)

$termStore = $taxSession.GetDefaultKeywordsTermStore()
$groups = $termStore.Groups
$ctx.Load($groups)
$ctx.ExecuteQuery()

foreach ($group in $groups)
{
    Write-Host "Group Name:" $group.Name "(Site Group: $($group.IsSiteCollectionGroup))"
}

What to verify?

1)Ensure the compatible version (version 16) of SharePoint Client Components SDK is used

2)Ensure site collection group really exist, for that purpose you could utilize the following script:

$taxSession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
$termStore = $taxSession.GetDefaultKeywordsTermStore()
$termGroup = $termStore.GetSiteCollectionGroup($ctx.Site,$true) //create site collection term group if it doesn't exist
$termStore.CommitAll()
$ctx.ExecuteQuery()
  • 1
    Thanks for the response, @Vadim. Your script works, but it turns out mine does as well. I wasn't looking at something properly. Thanks for your time. – Kirk Liemohn Oct 7 '15 at 17:49

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.