Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
AdamNaj / Add-TagToPages.ps1
Created Aug 30, 2017
Add SXA Tags to all SXA Pages
View Add-TagToPages.ps1
$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" } |
@AdamNaj
AdamNaj / Set-Layout.ps1
Created Aug 30, 2017
Set a layout for a device across multiple pages
View Set-Layout.ps1
# branch that should be replaced - change the path
$items = Get-ChildItem master:\content\home2 -WithParent
# layout I want to set on my items
$layout = Get-Item 'master:\layout\Layouts\Foundation\Experience Accelerator\MVC\MVC Layout'
# Device on which I want to set it
$device = Get-LayoutDevice "Mobile"
foreach($item in $items){
@AdamNaj
AdamNaj / CopyOrMove-Renderings.ps1
Last active Aug 29, 2017
Copy or Move renderings from one device to another (within Shared layout)
View CopyOrMove-Renderings.ps1
#branch that should be replaced - change the path
$items = Get-ChildItem master:\content\home2 -WithParent
#Provide the names for your devices from which and to which things should be copied
$fromDevice = Get-LayoutDevice "Default"
$toDevice = Get-LayoutDevice "Mobile"
# for Final layout renderings you need to add -FinalLayout switch to the Add/Remove-Rendering cmdlets
# and provide the -Language for which you want to perform the operation
@AdamNaj
AdamNaj / Test-RenderingUsage.ps1
Created Jun 5, 2017
What Items are using my rendering?!
View Test-RenderingUsage.ps1
Get-Item 'master:\layout\Renderings\Feature\Experience Accelerator\Media\Video' | Get-ItemReferrer | Show-ListView
@AdamNaj
AdamNaj / Test-Serialization.ps1
Created Jun 5, 2017
Unicorn vs Sitecore Serialization compare
View Test-Serialization.ps1
$sitecoreSerializationPath = "C:\inetpub\wwwroot\sitecore81\Data\serialization"
$unicornSerializationPath = "C:\Projects\sitecorepowershell\Trunk\Cognifide.PowerShell\serialization"
$serializationIds = gci $sitecoreSerializationPath -filter "*.item" -recurse | Get-Content -first 3 | ? { $_.Startswith("id:") } | % { $_.Substring(5,36).ToLower() }
$unicornIds = gci $unicornSerializationPath -filter "*.yml" -recurse | Get-Content -first 2 | ? { $_.Startswith("ID:") } | % { $_.Substring(5,36) }
"$($serializationIds.Count) items in Sitecore Serialization"
"$($unicornIds.Count) items in Unicorn Serialization"
Write-Host "---- Missing in Unicorn ----"
@AdamNaj
AdamNaj / Get-UserRoles.ps1
Last active Feb 6, 2017
List Roles for User
View Get-UserRoles.ps1
function Get-UserRoles{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0)]
[string]$Identity
)
$user = Get-User $Identity
return Get-Role -Filter * | Where-Object { $_.IsMember($user,$true,$true) }
}
@AdamNaj
AdamNaj / Relink-Test.ps1
Created Oct 14, 2016
Working with Links database
View Relink-Test.ps1