Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / UpdateADThumbnail.ps1
Created Feb 20, 2014
Update Active Directory thumbnail photo using PowerShell.
View UpdateADThumbnail.ps1
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 Aug 29, 2015
Scripts to archive Sitecore log files.
View Archive Logs.ps1
<#
.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 Aug 29, 2015
Provides reflection methods to extract version details.
View ApplicationDetails.cs
// 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 Oct 25, 2014
Delete unused media items older than 30 days in Sitecore
View Delete unused media items older than 30 days.ps1
<#
.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 Apr 8, 2015
New-UsingBlock and BulkUpdateContext changes Context User
View New-UsingBlock with BulkUpdateContext
function New-UsingBlock {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[IDisposable]
$InputObject,
[Parameter(Mandatory = $true)]
[ScriptBlock]
$ScriptBlock
@michaellwest
michaellwest / Count Items.ps1
Last active Aug 29, 2015
Count the number of content items excluding certain templates.
View Count Items.ps1
# 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
List Sitecore renderings and determine if cacheable
View List renderings.ps1
# 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 Aug 29, 2015
Quickly disable Sitecore Analytic configs
View Disable Sitecore 8 Analytic configs.ps1
$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 Aug 29, 2015
Function to list packages installed in a Sitecore instance.
View Get-PackageHistory.ps1
<#
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 Jun 30, 2015
The following example remotely executes a script in Sitecore using a reusable session.
View RemotelyInvokeScript.ps1
# 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