Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gist:5919737
Created July 3, 2013 15:58
Show me all template fields that define source, and what source do they define
Get-ChildItem master:\templates\ -recurse |? {$_.TemplateName -eq "Template Field" -and $_._Source -ne "" } | ft ProviderPath, _Source -auto
@AdamNaj
AdamNaj / ReadVariableSample.ps1
Last active December 20, 2015 21:49
Read-Variable Sample
$item = get-item master:\content\Demo\Int\Presentation\Designs
$parent = get-item . |% { $_.Parent }
$result = Read-Variable -Parameters `
@{ Name = "from"; Value=[System.DateTime]::Now.AddDays(-5); Title="Start Date"; Tooltip="Date since when you want the report to run"; ShowTime=$true}, `
@{ Name = "item"; Title="Start Item"; Root="/sitecore/content/"; Tooltip="Branch you want to analyse."}, `
@{ Variable = get-variable "parent" }, `
@{ Name = "silent"; Value=$true; Title="Proceed Silently"; Tooltip="Check this is you don't want to be interrupted"; }, `
@{ Name = "someText"; Value="Some Text"; Title="Text"; Tooltip="Tooltip for singleline"; }, `
@{ Name = "someMultilineText"; Value="Multiline Text"; Title="Text"; lines=3; Tooltip="Tooltip for multiline"; }, `
@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 / 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 / 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 / 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 / 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 / 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}}