Forum Discussion
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
- LeonPavesicSilver 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:
- Connect to SharePoint Online using the Connect-PnPOnline cmdlet.
- Get the term store using the Get-PnPTermStore cmdlet.
- Get the term set that you want to read the values from using the Get-PnPTermSet cmdlet.
- Get all the terms in the term set using the Get-PnPTerm cmdlet.
- Store the terms in an array variable.
- 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:
- SharePoint PnP PowerShell module documentation: https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets
- Connect-PnPOnline cmdlet documentation: https://pnp.github.io/powershell/cmdlets/Connect-PnPOnline.html
- Get-PnPTermStore cmdlet documentation: https://pnp.github.io/powershell/cmdlets/Get-PnPTerm.html
- Get-PnPTermSet cmdlet documentation: https://pnp.github.io/powershell/cmdlets/Get-PnPTerm.html
- Get-PnPTerm cmdlet documentation: https://pnp.github.io/powershell/cmdlets/Get-PnPTerm.html
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)- pratikdarak21Brass ContributorHi,
Get-PnPTermStore doesn't work in azure runbook.