Skip to content

Instantly share code, notes, and snippets.

@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 / Get-SitecoreLogTail.ps1
Created September 4, 2015 18:55
Get last 10 lines of the latest sitecore blog.
Get-ChildItem "$($SitecoreLogFolder)\log*.*" | Sort-Object -Descending LastWriteTime | Select-Object -First 1 | Get-Content -Tail 10
<#
.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 / 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}
@AdamNaj
AdamNaj / New-MediaItem.ps1
Last active July 23, 2016 12:43
Create Media item from file on server drive
function New-MediaItem{
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string]$filePath,
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$mediaPath)
@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 / Relink-Test.ps1
Created October 14, 2016 15:21
Working with Links database
@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 / Test-Dialogs.ps1
Last active December 5, 2016 14:28
Dialog Test Script
#Host Color test
$Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'White')
$Host.UI.RawUI.ForegroundColor = 'Black'
$Host.PrivateData.ErrorForegroundColor = 'Red'
$Host.PrivateData.ErrorBackgroundColor = $bckgrnd
$Host.PrivateData.WarningForegroundColor = 'Magenta'
$Host.PrivateData.WarningBackgroundColor = $bckgrnd
$Host.PrivateData.DebugForegroundColor = 'Blue'
$Host.PrivateData.DebugBackgroundColor = $bckgrnd
$Host.PrivateData.VerboseForegroundColor = 'Green'
#This script will create sitecore items based on given count and template
$InputCount=10
$InputTemplate = Get-Item "master:\templates\Sample\Sample Item"
$result = Read-Variable `
-Parameters @{Name="InputCount"; Title="How many items do you want to create?"},
@{Name="InputTemplate"; Title="Using which template you want to create item?"; root="/sitecore/templates/"} `
-Title "Bulk item create tool" `
-Description "Please provide the number of items and the template that you want to be used"
if($result -eq "ok"){