Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / ExportItemToXml.ps1
Created December 7, 2015 16:53
The following script generates an xml file with data from items using Sitecore PowerShell Extensions 3.3.
# SPE 4.0 has upgraded the New-UsingBlock function to a cmdlet
Import-Function New-UsingBlock
$stringWriterDefinition = @"
using System.IO;
using System.Text;
public sealed class StringWriterWithEncoding : StringWriter
{
private readonly Encoding encoding;
@michaellwest
michaellwest / Get-LockedChildItem
Created November 23, 2013 20:03
Function to retrieve locked items in the Sitecore CMS.
function Get-LockedChildItem {
<#
.SYNOPSIS
Gets the locked item at the specified location.
.PARAMETER Path
Specifies a path to search for locked items. The default location is the current directory (.).
.PARAMETER LockedBy
Specifies the the owner account locked on the item.
@michaellwest
michaellwest / TDS Package Version Target
Last active December 29, 2015 11:48
Hedgehog Team Development for Sitecore - Package version based on Assembly Version
<Import Project="$(MSBuildExtensionsPath)\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets" />
<ItemGroup>
<AssembliesPath Include="..\SomethingAwesome.Web\bin\SomethingAwesome.Web.dll" />
</ItemGroup>
<Target Name="BeforeSitecoreBuild">
<GetAssemblyIdentity AssemblyFiles="@(AssembliesPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<CreateProperty Value="%(AssemblyVersion.Version)">
<Output TaskParameter="Value" PropertyName="PackageVersion" />
@michaellwest
michaellwest / ReportDuplicateEmployeeID
Created January 17, 2014 17:09
Find users with duplicate employee ids.
# Get all the enabled users.
$users = Get-ADUser -Filter { Enabled -eq $true } -Properties EmployeeId
# Collect all the ids and format them to 7 characters.
$ids = @{}; $users | ForEach-Object { if($_.EmployeeId) { $ids[("{0:D7}" -f [int]$_.EmployeeId)] += 1 } }
$filteredUsers = $users | Where-Object { if($_.EmployeeId) { $ids[("{0:D7}" -f [int]$_.EmployeeId)] -gt 1 } }
$filteredUsers | Select-Object -Property SamAccountName, EmployeeId
$filteredUsers | Export-Csv -Path "C:\temp\DuplicateEmployeeId-$((Get-Date).ToString('yyyyMMddThhmmss')).csv" -NoTypeInformation
@michaellwest
michaellwest / App_Offline.htm.disabled
Last active January 4, 2016 00:49
Site maintenance files for IIS.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Down for Maintenance</title>
</head>
<body>
<div>&nbsp;</div>
<div id="wrapper">
<div id="page">
<div id="content">
@michaellwest
michaellwest / ImageToClipboard.reg
Created January 24, 2014 21:07
Copy the selected image to the clipboard. This allows you to paste the image content into an email or other programs.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\pngfile\shell\Copy image to clipboard]
@="Copy image to clipboard"
[HKEY_CLASSES_ROOT\pngfile\shell\Copy image to clipboard\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -Command \"Add-Type -AssemblyName 'PresentationFramework','PresentationCore';[System.Windows.Clipboard]::SetImage((New-Object System.Windows.Media.Imaging.BitmapImage ([System.Uri]'%1')))\""
[HKEY_CLASSES_ROOT\jpegfile\shell\Copy image to clipboard]
@="Copy image to clipboard"
@michaellwest
michaellwest / RenderingsReport.ps1
Last active January 11, 2016 16:20
Total number of Sublayouts in your Sitecore instance along with referrer pages and caching parameters
<#
Total number of Sublayouts in your Sitecore instance along with referrer pages and caching parameters
#>
$selectedItem = Get-Item -Path "master:\layout"
$result = Read-Variable -Parameters `
@{ Name = "selectedItem"; Title = "Please select the path to query"; Root="/sitecore/layout/"} -Width 500 -Height 280 -OkButtonName "Proceed" -CancelButtonName "Abort"
if($result -ne "ok") {
Close-Window
@michaellwest
michaellwest / MissingLanguageVersionReport.ps1
Last active January 13, 2016 22:22
Reports on all the content items missing a translation in Sitecore.
<#
.SYNOPSIS
Reports on all the content items missing a translation in Sitecore.
#>
$languageNames = Get-ChildItem -Path "master:\" -ID ([Sitecore.ItemIDs]::LanguageRoot) |
Select-Object -ExpandProperty Name
$groups = Get-ChildItem -Path "master:\content\" -Recurse -Language * | Group-Object -Property Name | Where-Object { $_.Count -lt $languageNames.Count }
@michaellwest
michaellwest / LASUG-Online2.ps1
Created January 22, 2016 04:00
Demo code used in the LASUG used in this Google Hangout: https://plus.google.com/events/cdagvle072duivnn0ms7td9h8t4
#region Setup
# The module should reside in $env:PSModulePath
Import-Module -Name SPE -Force
# Use Get-Help to see examples
$props = @{
Session = (New-ScriptSession -Username "admin" -Password "b" -ConnectionUri "http://console")
Verbose = $true
@michaellwest
michaellwest / GenerateTestUsers.ps1
Created January 30, 2016 02:10
Generate test users with a random generated name.
Import-Module SPE
$session = New-ScriptSession -Username "admin" -Password "b" -ConnectionUri "http://remotesitecore"
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
foreach($num in 0..10) {
$key = -join ((65..90) + (97..122) | Get-Random -Count 7 | % {[char]$_})
New-User -Identity "TestUser$($key)" -Enabled -Password "b" | Out-Null
}
} -AsJob