Skip to content

Instantly share code, notes, and snippets.

@AlexKasaku
AlexKasaku / gist:76d9d69e0d919eae2c54
Last active August 29, 2015 14:24
[Sitecore] Find items of a type, read a multilist field from there, get those items and summarise the relationship.
$courses = gci -r | where-object { $_.TemplateName -ne $null -and $_.TemplateName -eq 'CoursePage' }
ForEach ($course in $courses) {
$subjectAreaField = $course.SubjectArea
if ($subjectAreaField)
{
$subjectAreaIDs = $subjectAreaField -split '\|'
$subjectArray = @()
@AlexKasaku
AlexKasaku / gist:f12032590bbd208bb459
Created July 15, 2015 10:53
[Sitecore] Replace the DataSource found in a rendering of all child items
gci | % { $_.__Renderings = ($_.__Renderings -replace “{2E07CF1D-DE5B-4D5C-B226-024C549A652E}”,”{FC7EE80B-B784-4E70-9C7B-BCDCE631B67D}”) }
@AlexKasaku
AlexKasaku / gist:5c0c59e9d1600f643c10
Created July 15, 2015 10:54
[Sitecore] Get all items with a matching name, and update a field within that item
gci -r | where { $_.Name -eq "Apply2015" } | % { $_.Year = "{80B694E2-7FA4-449C-A1DF-07C3E44815CD}" }
@AlexKasaku
AlexKasaku / SerializeItemsWithMedia.ps1
Last active August 29, 2015 14:27
Serialize all child-items along with their related media items
<#
.SYNOPSIS
Serialize items AND related media items.
.NOTES
Alex Washtell
#>
filter Is-InMediaLibrary {
if($_.FullPath.StartsWith("/sitecore/media library")) {
@AlexKasaku
AlexKasaku / ChangeTemplate.ps1
Created August 13, 2015 14:33
Change template
$master = [Sitecore.Configuration.Factory]::GetDatabase("master");
$entryTemplate = $master.Templates["User Defined/xxx/Folders/Components Folder"];
Get-ChildItem -recurse | where Name -eq "Components" | % { $_.ChangeTemplate($entryTemplate) }
@AlexKasaku
AlexKasaku / RemoveMediaItems.ps1
Created August 20, 2015 13:45
Remove all media items that are not referenced.
<#
.SYNOPSIS
Removes all media items that are not linked to other items.
#>
# HasReference determines if the specified item is referenced by any other item.
function HasReference {
param(
$Item
)
@AlexKasaku
AlexKasaku / RemoveInvalidRedirects.ps1
Created August 21, 2015 09:51
Remove redirect items that are no longer pointed at an existing item
<#
.SYNOPSIS
Removes all Redirect URLs that do not have a valid destination
.NOTES
Alex Washtell
#>
# HasReference determines if the specified item is referenced by any other item.
filter NoValidDestination {
@AlexKasaku
AlexKasaku / RemoveEmptyFolders.ps1
Created August 21, 2015 10:08
Removes empty folders
<#
.SYNOPSIS
Removes empty folders
#>
filter NoChildren {
if ($_.Children.Count -eq 0) {
$_
}
@AlexKasaku
AlexKasaku / UpdateItems.ps1
Created August 21, 2015 10:15
Update a bunch of items to edit a field
<#
.SYNOPSIS
Updates a field in a set of items
#>
$items = Get-ChildItem -Recurse | Where TemplateName -eq "Redirect Url"
foreach( $item in $items ) {
if ($item."Requested Url".StartsWith("/sitecore") ) {
@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 {