Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
Created August 30, 2017 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamNaj/80fe4f86531b7c1b43bb69fd0f9cc52b to your computer and use it in GitHub Desktop.
Save AdamNaj/80fe4f86531b7c1b43bb69fd0f9cc52b to your computer and use it in GitHub Desktop.
Add SXA Tags to all SXA Pages
$sitePath = "master:\content\Demo\Origin"
#get items but only those that are SXA pages
$pages = Get-ChildItem "$sitePath\Home" -Recurse -WithParent |
Where-Object { Test-BaseTemplate -Item $_ -Template "Foundation/Experience Accelerator/Multisite/Content/Page" }
#you can pipe it to further filtering here if you want to do it only for some pages
#get tag items that contain the word "Adam" in them
$tags = (@() + (Get-ChildItem "$sitePath\Data\Tags" -Recurse |
Where-Object { Test-BaseTemplate -Item $_ -Template "Feature/Experience Accelerator/Taxonomy/Datasource/Tag" } |
Where-Object { $_.Name -like "*Adam*" })).ID
if($tags.Count -gt 0){
foreach($page in $pages){
#for every page add the tags - make sure they are uniquely used and tags are not added twice.
$page.SxaTags = (@() + $page._.SxaTags.GetItems().ID + $tags | select -Unique) -join "|"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment