Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
AdamNaj / AuditTemplates.png
Last active February 6, 2017 13:21
Template Usage Audit script
AuditTemplates.png
@AdamNaj
AdamNaj / Read-Variable Field Validation.png
Last active October 22, 2016 03:24
Read-Variable field validation
Read-Variable Field Validation.png
@AdamNaj
AdamNaj / Relink-Test.ps1
Created October 14, 2016 15:21
Working with Links database
@AdamNaj
AdamNaj / Export-ZGShowcase.ps1
Last active August 22, 2016 16:45
ZG Showcase migration
$orderNo=0
$siteDef = gci "master:\content\Showcase Group\Showcase\int\home" -Recurse |
? { $_.Name -ne "Data" -and $_.Parent.Name -ne "Data" -and $_.Parent.Parent.Name -ne "Data" -and $_.Parent.Parent.Parent.Name -ne "Data" -and $_.Parent.Name -ne "Page Data" -and $_.Visualization.Layout -ne $null} |
%{
$orderNo++;
$pageDefinition = [ordered]@{
Name="$($_.Name)";
DisplayName="$($_.DisplayName)";
@AdamNaj
AdamNaj / Get-TemplateComplexity.ps1
Created April 20, 2016 13:32
Template Complexity analysis
$standardFieldCount = (Get-ItemTemplate master:\).Fields.Count
Get-ChildItem master:\templates -Recurse |
? {($_.TemplateName -eq "Template") -and -not $_.FullPath.StartsWith('/sitecore/templates/System')} |
% { [Sitecore.Data.Items.TemplateItem]$template = $_
[pscustomobject]@{
Path=&{$_.FullPath};
OnThisTemplate=&{(Get-ChildItem -Path $_.Providerpath -Recurse | ? { $_.TemplateName -eq "Template Field"}).Count};
NonStandardFields =&{$template.Fields.Count- $standardFieldCount};
TotalFields=&{$template.Fields.Count}
<#
.SYNOPSIS
Extracts the compressed file to to the specified directory.
.PARAMETER Item
Specifies the item to be exported as PDF/JPG/PNG.
.EXAMPLE
The following eports the Home page by piping an item into the cmdlet.
@AdamNaj
AdamNaj / Archive-OldItemVersion.ps1
Created March 2, 2016 21:35
Archive old item versions
function Archive-OldItemVersion {
[CmdletBinding()]
param(
[Parameter(Position = 0,Mandatory = $true,ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[Sitecore.Data.Items.Item]$Item,
[Parameter(Position = 1,Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[int]$MaxVersions
)
@AdamNaj
AdamNaj / List-ActiveFunctions.ps1
Created February 29, 2016 09:05
List Active Functions
[Cognifide.PowerShell.Core.Modules.ModuleManager]::GetFeatureRoots([Cognifide.PowerShell.Core.Modules.IntegrationPoints]::FunctionsFeature) |
Initialize-Item |
%{ $_.ProviderPath } |
%{ Get-ChildItem -Path $_ } |
?{ $_.TemplateName -eq "PowerShell Script" } |
ft Database, Name, @{Label="Parent"; Expression={ $_.Parent.Name}}
@AdamNaj
AdamNaj / Get-Parameters.ps1
Created February 12, 2016 12:15
What parameters are used by your commandlets and how many times are they defined?
$cmds = Get-Command -CommandType Cmdlet #| select -ExpandProperty Parameters #| #| ft name, count #-Property # % { $_.Keys } | Sort -Unique
#$cmds[733].Name
#$cmds[733].Parameters | gm
$parameters = [ordered]@{};
$cmds | % {
if($_.Parameters.Keys.Count -gt 0){
foreach($param in $_.Parameters.Keys){
if($param -ne $null -and -not $parameters.Contains($param)){
$parameters.Add($param, $_.Name)
} else {
@AdamNaj
AdamNaj / Remove-UnusedMediaItems.ps1
Last active February 6, 2016 16:50
Remove unused media items
#Include all paths you do not want to analyse below
$protectedPaths = @(
"/sitecore/media library/System/",
"/sitecore/media library/Experience Explorer"
"/sitecore/media library/Images/Social"
);
#Include all item templates you want to ignore in the array below
$protectedTemplates = @(
[Sitecore.TemplateIDs]::MediaFolder