Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / PublishSC7Items.ps1
Created February 14, 2016 01:51
Publish the direct children of the home item and any related linked items for Sitecore 7.0 on SPE 4.
$targetDatabaseFieldId = New-Object Sitecore.Data.ID "{39ECFD90-55D2-49D8-B513-99D15573DE41}"
$targets = @()
foreach($publishingTarget in [Sitecore.Publishing.PublishManager]::GetPublishingTargets((Get-Database -Name "master"))) {
$targets += $publishingTarget[$targetDatabaseFieldId]
}
$publishingCandidates = Get-ChildItem -Path "master:\content\home"
$databases = Get-Database | Where-Object { $targets -contains $_.Name }
$relatedItems = @()
@michaellwest
michaellwest / GetChildItemExcludingPath.ps1
Created February 17, 2016 23:37
Gets the child items excluding paths specified in a list.
$source = "C:\inetpub\wwwroot\MySite"
Set-Location $source
#----------------------
# exclude locations
#----------------------
$ignoreFolder = @()
$ignoreFolder += "\Website\App_Data"
$ignoreFolder += "\Website\temp"
@michaellwest
michaellwest / Get-PublishJob.ps1
Created April 15, 2016 17:31
Lists the publishing jobs in Sitecore.
Get-Item -Path "master:\media library" | Publish-Item -PublishMode Smart -Recurse
function Get-PublishJob {
[CmdletBinding(DefaultParameterSetName="All")]
param(
[Parameter(Mandatory,ParameterSetName="State")]
[Sitecore.Jobs.JobState]$State,
[Parameter(Mandatory,ParameterSetName="Id")]
[string]$Id
@michaellwest
michaellwest / Set-SubItemSortOrder.ps1
Created April 16, 2016 05:27
Sets the subitem sort order for Sitecore items.
function Set-SubItemSortOrder {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Path,
[Parameter(Mandatory,ParameterSetName="SortOrder")]
[ValidateSet("Created", "Default", "DisplayName", "Logical", "Reverse", "Updated")]
[string]$SortOrder,
@michaellwest
michaellwest / CompareFolders.ps1
Last active May 3, 2016 23:18
Compares the different between two folders.
function Compare-Folder {
param(
[string]$LeftFolder,
[string]$RightFolder
)
$LeftSideHash = Get-ChildItem $LeftFolder -Recurse | Get-FileHash -Algorithm SHA1 |
Select-Object @{Label="Path";Expression={$_.Path.Replace($LeftFolder,"")}},Hash
$RightSideHash = Get-ChildItem $RightFolder -Recurse | Get-FileHash -Algorithm SHA1 |
Select-Object @{Label="Path";Expression={$_.Path.Replace($RightFolder,"")}},Hash
@michaellwest
michaellwest / CopyUserProfileProperties.ps1
Last active May 21, 2016 05:01
Copy User Profile Properties using SPE.
$user1 = Get-User -Identity michael1
$user2 = Get-User -Identity michael2 -Authenticated
$user2.Profile.ProfileItemId = $user1.Profile.ProfileItemId
$user2.Profile.Portrait = $user1.Profile.Portrait
foreach($customPropertyName in $user1.Profile.GetCustomPropertyNames()) {
$customPropertyValue = $user1.Profile.GetCustomProperty($customPropertyName)
$user2.Profile.SetCustomProperty($customPropertyName, $customPropertyValue)
}
@michaellwest
michaellwest / 01-Setup.ps1
Created May 18, 2016 05:01
Milwaukee Sitecore User Group Meetup scripts. 2016-05-17.
<#
.SYNOPSIS
Remoting setup
.DESCRIPTION
The following list describes the key setup requirements to get SPE Remoting working.
- Deploy SPE Remoting module
- Windows PowerShell Module : SPE Remoting-4.0.zip
- Usual Path : C:\Users\micha\Documents\WindowsPowerShell\Modules\SPE
@michaellwest
michaellwest / Cognifide.PowerShell.Services.config
Last active September 14, 2016 14:23
Sitecore PowerShell Extensions Workshop - Sitecore Symposium 2016
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<powershell>
<services>
<mediaUpload>
<patch:attribute name="enabled">true</patch:attribute>
</mediaUpload>
<fileDownload>
<patch:attribute name="enabled">true</patch:attribute>
</fileDownload>
@michaellwest
michaellwest / RunQueueCleanup.ps1
Created October 24, 2016 20:57
Creates a new job for each cleanup agent using Sitecore PowerShell Extensions.
foreach($node in [Sitecore.Configuration.Factory]::GetConfigNodes("scheduling/agent") | Where-Object { $_.Type -like "*CleanupPublishQueue*" -or $_.Type -like "*CleanupEventQueue*" -or $_.Type -like "*CleanupHistory*"}) {
$obj = [Sitecore.Configuration.Factory]::CreateObject($node, $true)
$name = [Sitecore.Xml.XmlUtil]::GetAttribute("type", $node)
$method = [Sitecore.Xml.XmlUtil]::GetAttribute("method", $node)
$options = New-Object Sitecore.Jobs.JobOptions $name, "", "", $obj, $method
$options.AtomicExecution = $true
$options.SiteName = "website"
[Sitecore.Jobs.JobManager]::Start($options)
}
@michaellwest
michaellwest / ReassignjQueryHide.js
Created October 24, 2016 20:58
Reassign the jQuery hide function and log the caller to the console.
var orig = jQuery.fn.hide;
jQuery.fn.hide = function () { console.log("hiding elements", arguments.callee.caller.toString()); orig.apply(this, arguments);}