Forum Discussion

pratikdarak21's avatar
pratikdarak21
Brass Contributor
Oct 17, 2023

How to read sharepoint online site collection taxonomy values in Azure Runbook

Hi,

 

How can I read SharePoint online site collection taxonomy values in Azure Runbook PowerShell and store those values in array variable ?

 

Regards,

Pratik

  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi pratikdarak21,

    To read SharePoint Online site collection taxonomy values in Azure Runbook PowerShell and store those values in an array variable, you can use the following steps:

    1. Connect to SharePoint Online using the Connect-PnPOnline cmdlet.
    2. Get the term store using the Get-PnPTermStore cmdlet.
    3. Get the term set that you want to read the values from using the Get-PnPTermSet cmdlet.
    4. Get all the terms in the term set using the Get-PnPTerm cmdlet.
    5. Store the terms in an array variable.
    6. Disconnect from SharePoint Online using the Disconnect-PnPOnline cmdlet.

    The following PowerShell code shows how to read SharePoint Online site collection taxonomy values in Azure Runbook PowerShell and store those values in an array variable:

     

     

    # Connect to SharePoint Online
    Connect-PnPOnline -Url "https://contoso.sharepoint.com" -Credentials $myCredentials
    
    # Get the term store
    $termStore = Get-PnPTermStore
    
    # Get the term set that you want to read the values from
    $termSet = Get-PnPTermSet -TermStore $termStore -TermSetName "My Term Set"
    
    # Get all the terms in the term set
    $terms = Get-PnPTerm -TermSet $termSet
    
    # Store the terms in an array variable
    $termArray = @()
    foreach ($term in $terms) {
        $termArray += $term.Name
    }
    
    # Disconnect from SharePoint Online
    Disconnect-PnPOnline
    
    # Output the terms in the array variable
    foreach ($term in $termArray) {
        Write-Host $term
    }

     

     

    You can then use the $termArray variable in your Azure Runbook to perform other tasks, such as logging the terms to a file or sending them in an email.

    Here are some documentation links:


    Please click Mark as Best Response & Like if my post helped you to solve your issue.
    This will help others to find the correct solution easily. It also closes the item.


    If the post was useful in other ways, please consider giving it Like.


    Kindest regards,


    Leon Pavesic
    (LinkedIn)

Resources