Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / UpdateADThumbnail.ps1
Created February 20, 2014 15:01
Update Active Directory thumbnail photo using PowerShell.
Import-Module ActiveDirectory
Set-ADUser -Identity "Michael.West" -Replace @{"thumbnailPhoto" = [byte[]](Get-Content -Path "michael.jpg" -Encoding Byte)}
@michaellwest
michaellwest / Archive Logs.ps1
Last active August 29, 2015 14:00
Scripts to archive Sitecore log files.
<#
.SYNOPSIS
Archives old log files int zip format to a separate archive directory.
.NOTES
Michael West
#>
<#
Load the function Compress-Archive. The Get-Item command supports a dynamic parameter
@michaellwest
michaellwest / ApplicationDetails.cs
Last active August 29, 2015 14:06
Provides reflection methods to extract version details.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
using System.Text;
using Sitecore.SharedSource.Reflection;
using Sitecore.Pipelines.GetAboutInformation;
namespace Sitecore.SharedSource.Pipelines
{
public class ApplicationDetails
@michaellwest
michaellwest / Delete unused media items older than 30 days.ps1
Created October 25, 2014 03:45
Delete unused media items older than 30 days in Sitecore
<#
.SYNOPSIS
Moves items to the recycle bin which are more than 30 days old and have no references.
.NOTES
Michael West
#>
filter Skip-MissingReference {
$linkDb = [Sitecore.Globals]::LinkDatabase
@michaellwest
michaellwest / New-UsingBlock with BulkUpdateContext
Created April 8, 2015 12:49
New-UsingBlock and BulkUpdateContext changes Context User
function New-UsingBlock {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[IDisposable]
$InputObject,
[Parameter(Mandatory = $true)]
[ScriptBlock]
$ScriptBlock
@michaellwest
michaellwest / Count Items.ps1
Last active August 29, 2015 14:18
Count the number of content items excluding certain templates.
# List of template ids to exclude from the count.
$templateIds = @(
"{29FD19B5-6F81-4829-B725-9C4279DA13CE}",
"{C3C9ED41-B476-49A9-B50C-FF8901665EA0}",
"{5A905A62-4898-44CE-96BA-EB3432BAAD91}"
)
@(Get-Item -Path master:\content\home) + @(Get-ChildItem -Path master:\content\home -Recurse) |
Where-Object { $templateIds -notcontains $_.TemplateId } |
Select-Object -Property Name, TemplateId |
@michaellwest
michaellwest / List renderings.ps1
Created May 16, 2015 22:14
List Sitecore renderings and determine if cacheable
# http://www.layerworks.com/blog/2015/4/17/sitecore-powershell-script-examples
$VerbosePreference = "continue"
$path = "master:/sitecore/layout/renderings"
Write-Log "Get all renderings and determine if caching is enabled."
Get-ChildItem -Path $path -Recurse |
Where-Object { $_.TemplateName -ne "Rendering Folder" } |
Format-Table -AutoSize -Property Name, ItemPath, ID, @{"Name"="Cacheable";"Expression"={$_.Cacheable -eq "1"}}
@michaellwest
michaellwest / Disable Sitecore 8 Analytic configs.ps1
Last active August 29, 2015 14:21
Quickly disable Sitecore Analytic configs
$paths = @("C:\inetpub\wwwroot\Console\Website\App_Config\Include\*","C:\inetpub\wwwroot\Demo\Website\App_Config\Include\*")
$patterns = @("Sitecore.Analytics*.config", "Sitecore.ExperienceAnalytics*.config")
$paths | Get-ChildItem -Include $patterns -Recurse | Rename-Item -NewName { $PSItem.Name + ".disabled" }
@michaellwest
michaellwest / Get-PackageHistory.ps1
Last active August 29, 2015 14:23
Function to list packages installed in a Sitecore instance.
<#
Adapted from the Package History module found here:
https://marketplace.sitecore.net/en/Modules/PackageHistory.aspx
#>
function Get-PackageHistory {
$packageHistoryPath = "/sitecore/system/Packages/Installation history"
$packageRegistrationTemplateId = "{22A11D20-5F1D-4216-BF3F-18C016F1F98E}"
$coreDb = Get-Database -Name "core"
$historyItem = $coreDb.GetItem($packageHistoryPath)
@michaellwest
michaellwest / RemotelyInvokeScript.ps1
Created June 30, 2015 13:29
The following example remotely executes a script in Sitecore using a reusable session.
# The following example remotely executes a script in Sitecore using a reusable session.
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://remotesitecore
Invoke-RemoteScript -Session $session -ScriptBlock { Get-User -id admin }
Name Domain IsAdministrator IsAuthenticated
---- ------ --------------- ---------------
sitecore\admin sitecore True False