Skip to content

Instantly share code, notes, and snippets.

@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
@AdamNaj
AdamNaj / Add-Remove-ItemVersion-Test.ps1
Last active January 11, 2016 02:19
Add-ItemVersion & Remove-ItemVersion tests
$testPath = "master:\content\item-test"
$targetLang = "pl-PL"
$format = @{Property = @("ID", "Name", "Language", "Version", "Text"); AutoSize=$true }
$giParams = @{Path=$testPath; Version="*"; }
Set-HostProperty -HostWidth 180
& {
if(Test-Path $testPath){
Remove-Item $testPath -Force -Recurse
}
@AdamNaj
AdamNaj / Variable-Tooltip-Test.ps1
Created January 6, 2016 19:52
Variable tooltip test
$item = Get-Item master:\content\home
$items = Get-ChildItem master:\
$int = 1337
$float = 13.37
$bool = $true
$date = Get-Date
$string = "A string value"
$user = Get-User "sitecore\admin"
$table = @{"Name" = "Sitecore PowerShell"; "Date" = [datetime]::Now}
$list = @("Sitecore","PowerShell", [datetime]::now)
@AdamNaj
AdamNaj / Remove-OldItemVersion.ps1
Last active March 3, 2021 22:21
Item Version Pruner
function Remove-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 / Publish-Workaround.ps1
Last active December 2, 2015 15:44
Deep and through republishing workaround, single language
function Publish-Workaround {
[CmdletBinding()]
param(
[Parameter(Position = 0,Mandatory = $true,ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[Sitecore.Data.Items.Item]$item,
[Parameter(Position = 1,Mandatory = $true,ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[Sitecore.Data.Database]$target
)
@AdamNaj
AdamNaj / Set-ItemFieldToExternalLink.ps1
Created October 26, 2015 20:47
Set item field to external url
#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"){
@AdamNaj
AdamNaj / 00_Get-ItemsChangedInLast7Days.ps1
Last active February 24, 2016 16:24
SUGCON Presentation
$days = 7;
Get-ChildItem master:\content\home -Recurse |
? { $_."__updated" -gt (Get-Date).AddDays(-$days) } |
Format-Table -Property ID, Name, "__updated", "__updated by"
@AdamNaj
AdamNaj / Fix-ZGCars.ps1
Created September 27, 2015 03:29
Fix ZG Cars media
Get-childitem "master:/media library/Showcase-Group/search/int/images/cars" -rec |
? { $_."File Path" -ne $null } |
% { $_."File Path" = $_."File Path" -replace "/Replicated", "" }
@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)