Skip to content

Instantly share code, notes, and snippets.

@AlexKasaku
AlexKasaku / ExportItemLayouts.ps1
Last active November 3, 2016 11:59
Export item layouts based on a list of item paths
$defaultDevice = Get-LayoutDevice "Default"
$paths = @(
"/sitecore/content/home",
)
$paths | Get-Item -Path master:$path | Select ID, FullPath, @{Name="Final Layout";Expression={$_."__Final Renderings"}} | Show-ListView
@AlexKasaku
AlexKasaku / MoveFinalRenderingsToShared.ps1
Last active November 2, 2016 18:47
Move Final Renderings value to Shared for Standard Values
$results = @();
foreach ( $item in Get-ChildItem -Recurse )
{
if ($item.Name -ne "__Standard Values") {
continue;
}
$result = New-Object System.Object
$result | Add-Member -type NoteProperty -name ID -value $item.ID
@AlexKasaku
AlexKasaku / ExamineRenderings.ps1
Last active October 21, 2016 11:01
Examine renderings in Standard Values to find uses of Shared + Final
$results = @();
foreach ( $item in Get-ChildItem -Recurse )
{
if ($item.Name -ne "__Standard Values") {
continue;
}
$result = New-Object System.Object
$result | Add-Member -type NoteProperty -name ID -value $item.ID
@AlexKasaku
AlexKasaku / Find Rendering By Parameter And ID.ps1
Created September 12, 2016 13:33
Find Rendering By Parameter And ID
$rendering = Get-Item -Path master:/sitecore/layout/Renderings/Website/Components/Path
foreach ( $item in Get-ChildItem -Path master:/sitecore/content/Home -WithParent )
{
$params = @{ "param" = "*" }
$renderings = Get-Rendering -Item $item -Rendering $rendering -FinalLayout -Parameter $params
if ($renderings.Count -gt 0)
{
# This item has a rendering with the parameter
@AlexKasaku
AlexKasaku / Find Rendering By Parameter.ps1
Created September 12, 2016 11:57
Find items that have a Rendering that uses a particular parameter
foreach ( $item in Get-ChildItem -Path master:/sitecore/content/Home -WithParent -Recurse )
{
$params = @{ "paramName" = "*" }
$renderings = Get-Rendering -Item $item -Parameter $params
if ($renderings.Count -gt 0)
{
# This item has a rendering with the parameter
$item.FullPath
}
# Convert items' Final Layout to an XML Delta version.
$defaultDevice = Get-LayoutDevice "Default"
foreach ( $item in Get-ChildItem -Recurse )
{
# Confirm item has a layout
try {
# Get-Layout can throw an error if layout is badly formed, so we catch it and continue if this happens.
if ((Get-Layout -Item $item -Device $defaultDevice) -eq $null) {
@AlexKasaku
AlexKasaku / Get-MediaItems.ps1
Created February 29, 2016 23:44
Use Receive-RemoteItem to get media items.
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://sc81rev151003
Invoke-RemoteScript -Session $session -ScriptBlock {
Get-ChildItem -Path "master:/sitecore/media library/Test" -Recurse | ?{ $_.Size -gt 0 } | Select -Expand ItemPath
} | Receive-RemoteItem -Session $session -Destination "C:\temp\Images\Downloaded\" -Database master
@AlexKasaku
AlexKasaku / Send-MediaItems.ps1
Created February 29, 2016 23:44
Use SPE Remoting to upload media items, maintaining folder structure
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://sc81rev151003/
$baseFolder = "C:\Temp\Images\ToUpload\"
$baseItemPath = "master:/sitecore/media library/Test/"
# Get folder structure, renaming to suit the Sitecore path
$foldersToCreate = Get-ChildItem -Path $baseFolder -Recurse | ?{ $_.PSIsContainer } | % { $_.FullName -replace [regex]::escape($baseFolder), $baseItemPath -replace "\\", "/" }
$args = @{
"paths" = $foldersToCreate
@AlexKasaku
AlexKasaku / ListFilesWithExceptions.ps1
Created February 18, 2016 10:41
List contents of folder, ignoring certain folders.
$source = "C:\Sites\bma8"
Set-Location $source
$ignoreFolder = @()
$ignoreFolder += "\Website\App_Data"
$ignoreFolder += "\Website\temp"
$ignoreFolder += "\Data\debug"
$ignoreFolder += "\Data\diagnostics"
$ignoreFolder += "\Data\indexes"
$ignoreFolder += "\Data\logs"
@AlexKasaku
AlexKasaku / IsOfTemplateFilter.ps1
Last active December 22, 2018 13:26
Filter to determine if an item derives from a particular template
Function Where-TemplateDerives {
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[Sitecore.Data.Items.Item]$Item,
[Parameter(Mandatory=$true,Position=0)]
[string]$TemplateID
)
process {