Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
AdamNaj / Clone Site.ps1
Created June 13, 2018 05:08
Modify SXA "Clone Site" script to be able to clone sites with Security set up on them.
# Open the following item:
# /sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Multisite/Content Editor/Context Menu/Clone Site
# inside the try{ } clause wrap its content with:
New-UsingBlock(New-Object -TypeName "Sitecore.SecurityModel.SecurityDisabler"){
# all code that was inside the try clause before - goes here
}
@AdamNaj
AdamNaj / Add-ProjectSpecificComponentDatasource.ps1
Last active September 29, 2017 17:06
Create project specific datasource templates for your SXA tenant so you can extend them with custom fields - Promo on Showcase example
###### user settings start here
# Path to the tenant that you want to update
$tenantTemplatesPath = "master:\templates\Project\Showcase"
# Site that should be upgraded to the new template - ise asterisk to upgrade multiple sites.
$sitePath = "master:\content\Showcase\*"
# Path to the component for which you want to introduce your own data source
$componentPath = 'master:\layout\Renderings\Feature\Experience Accelerator\Page Content\Promo'
@AdamNaj
AdamNaj / Convert-EventsToSearchable.ps1
Created September 15, 2017 10:21
Better Events List Script - Convert SXA Events templates into searchable items
$tenantTemplatesPath = "master:\templates\Project\Showcase"
$sitePath = "master:\content\Showcase\int"
function Assert-FeatureTemplateInProject {
[CmdletBinding()]
param(
[parameter(Mandatory=$true)]
[String[]] $TenantTemplateFolder,
[parameter(Mandatory=$true)]
@AdamNaj
AdamNaj / Add-TagToPages.ps1
Created August 30, 2017 16:45
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" } |
@AdamNaj
AdamNaj / Set-Layout.ps1
Created August 30, 2017 15:39
Set a layout for a device across multiple pages
# 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 August 29, 2017 20:55
Copy or Move renderings from one device to another (within Shared layout)
#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 June 5, 2017 15:08
What Items are using my rendering?!
Get-Item 'master:\layout\Renderings\Feature\Experience Accelerator\Media\Video' | Get-ItemReferrer | Show-ListView
@AdamNaj
AdamNaj / Test-Serialization.ps1
Created June 5, 2017 14:38
Unicorn vs Sitecore Serialization compare
$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 / Screenshot.png
Last active April 10, 2017 11:23
SXA Folder Synchronizer
Screenshot.png
@AdamNaj
AdamNaj / Get-UserRoles.ps1
Last active February 6, 2017 13:53
List Roles for User
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) }
}