Skip to content

Instantly share code, notes, and snippets.

@Wesley-Lomax
Wesley-Lomax / CountItemsMatchingTemplateInTree.ps1
Created March 23, 2018 13:44
Get Count of all Sitecore Items in list of templates in content tree
<#
SYNOPSIS
Does a simple count of all items in the specified templates
INSTRUCTIONS
After Get-Item -Path, type the path of the parent you want to start with.
EX: master:\sitecore\content\sites\example
Put the same path after Get-ChildItem, which will crawl through and find all child pages.
It'll display the number
@Wesley-Lomax
Wesley-Lomax / GetItemsWhereTemplateMatches.ps1
Last active March 23, 2018 13:42
List all Sitecore items where template is in a predefined list and location in the content tree, display in ListView
<#
SYNOPSIS
Does a simple count of all items in the specified templates
INSTRUCTIONS
After Get-Item -Path, type the path of the parent you want to start with.
EX: master:\sitecore\content\sites\example
Put the same path after Get-ChildItem, which will crawl through and find all child pages.
#>
@Wesley-Lomax
Wesley-Lomax / ClearSitecoreLogsDirectory.ps1
Created August 24, 2017 08:52
Delete Sitecore Log File Directory - Local Dev
gci C:\inetpub\wwwroot\RCN\Data\logs -Recurse -Filter *.txt | where{-not $_.PsIsContainer}| sort CreationTime -desc| select -Skip 0 | Remove-Item -Force
@Wesley-Lomax
Wesley-Lomax / HTTPResponseCodeStep.json
Created July 31, 2017 13:07
Octopus Depoy - Check for HTTP Response Code
{
"Id": "ActionTemplates-3",
"Name": "HTTP - Test URL",
"Description": "Makes a GET request to a HTTP(S) end point and verifies that a particular status code is returned within a specified period of time",
"ActionType": "Octopus.Script",
"Version": 1,
"Properties": {
"Octopus.Action.Script.ScriptBody": "$uri = $OctopusParameters['Uri']\n$expectedCode = [int] $OctopusParameters['ExpectedCode']\n$timeoutSeconds = [int] $OctopusParameters['TimeoutSeconds']\n$Username = $OctopusParameters['AuthUsername']\n$Password = $OctopusParameters['AuthPassword']\n$UseWindowsAuth = $OctopusParameters['UseWindowsAuth']\n\nWrite-Host \"Starting verification request to $uri\"\nWrite-Host \"Expecting response code $expectedCode.\"\n\n$timer = [System.Diagnostics.Stopwatch]::StartNew()\n$success = $false\ndo\n{\n try\n {\n if ($Username -and $Password -and $UseWindowsAuth)\n\t\t\t{\n\t\t\t Write-Host \"Making request to $uri using windows authentication for user $Username\"\n\t\t\t $request = [s
@Wesley-Lomax
Wesley-Lomax / fileZip.ps1
Created July 31, 2017 12:59
Octopus Deploy - File System Zip Step
$SourceDirectoryName = $OctopusParameters['SourceDirectoryName']
$DestinationArchiveFileName = $OctopusParameters['DestinationArchiveFileName']
$CompressionLevel = $OctopusParameters['CompressionLevel']
$IncludeBaseDirectory = $OctopusParameters['IncludeBaseDirectory']
$OverwriteDestination = $OctopusParameters['OverwriteDestination']
if (!$SourceDirectoryName)
{
Write-Error "No Source Directory name was specified. Please specify the name of the directory to that will be zipped."
exit -2
@Wesley-Lomax
Wesley-Lomax / migrateWithBaseTemplateCheck.ps1
Last active July 21, 2017 12:53
Sitecore Powershell Migrate Field value whilst checking if field exists and its from Base template
$_BaseTitleTemplate = Get-Item 'master:/sitecore/templates/User Defined/RCN/Base/_Base Title'
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
foreach($item in Get-ChildItem -Path "master:\content\" -recurse) {
if (![string]::ISNullOrEmpty($item."Title"))
{
$itemTemplate = Get-ItemTemplate -Item $item
foreach($baseTemplate in $itemTemplate.BaseTemplates) {
@Wesley-Lomax
Wesley-Lomax / StopAndStartAppPool.ps1
Created July 3, 2017 12:33
Start and Stop and App Pool with PowerShell
Write-Host "Stopping AppPool"
Stop-WebAppPool -Name AppPool
Write-Host "Starting AppPool"
Start-WebAppPool -Name AppPool
@Wesley-Lomax
Wesley-Lomax / CleanQueues.sql
Created April 26, 2017 10:21
Clean up Sitecore Event, Publish and Hiostory Queues
/****** History ******/
delete FROM [YOURDATABASE_Core].[dbo].[History] where Created < DATEADD(HOUR, -12, GETDATE())
delete FROM [YOURDATABASE_Master].[dbo].[History] where Created < DATEADD(HOUR, -12, GETDATE())
delete FROM [YOURDATABASE_Web].[dbo].[History] where Created < DATEADD(HOUR, -12, GETDATE())
/****** Publishqueue ******/
delete FROM [YOURDATABASE_Core].[dbo].[PublishQueue] where Date < DATEADD(HOUR, -12, GETDATE());
delete FROM [YOURDATABASE_Master].[dbo].[PublishQueue] where Date < DATEADD(HOUR, -12, GETDATE());
delete FROM [YOURDATABASE_Web].[dbo].[PublishQueue] where Date < DATEADD(HOUR, -12, GETDATE());
@Wesley-Lomax
Wesley-Lomax / UnicornItemsMoveFolder.json
Last active July 3, 2017 10:36
Move Unicorn items out of webroot into data folder with Octopus Step
{
"Id": "ActionTemplates-23",
"Name": "Move Unicorn files out of webroot",
"Description": "Moves Unicorn yml files from Website folder to Data folder after nuget deploy",
"ActionType": "Octopus.Script",
"Version": 21,
"Properties": {
"Octopus.Action.Package.NuGetFeedId": "feeds-builtin",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
@Wesley-Lomax
Wesley-Lomax / OctopusUnicornSync.json
Last active April 12, 2017 15:49
Octopus Deployment Step for Unicorn sync over https using TLS1.2
{
"Id": "ActionTemplates-22",
"Name": "Unicorn Sync over https",
"Description": "Calls the unicorn sync over https using TLS1.2",
"ActionType": "Octopus.Script",
"Version": 8,
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = 'Stop'\r\n\r\nAdd-Type -Path \"${MicroChap}\\MicroCHAP.dll\"\r\n\r\n\r\nAdd-Type @\"\r\n using System.Net;\r\n using System.Security.Cryptography.X509Certificates;\r\n public class TrustAllCertsPolicy : ICertificatePolicy {\r\n public bool CheckValidationResult(\r\n ServicePoint srvPoint, X509Certificate certificate,\r\n WebRequest request, int certificateProblem) {\r\n return true;\r\n }\r\n }\r\n\"@\r\n[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy\r\n\r\nFunction Sync-Unicorn {\r\n\tParam(\r\n\t\t[Parameter(Mandatory=$True)]\r\n\t\t[string]$ControlPanelUrl,\r\n\r\n\t\t[Parameter(Mandatory=$True)]\