Skip to content

Instantly share code, notes, and snippets.

@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"; }, `
#item I want to set the field on
$item = get-item "master:/content/home"
#image I want to use
$image = new-object -TypeName "Sitecore.Data.Items.MediaItem" -ArgumentList (get-item "master:/media library/Showcase/cognifide_logo")
#field I want to set on $item
$imageField = [Sitecore.Data.Fields.ImageField]$item.Fields["image"];
$item.Editing.BeginEdit();
$item = get-item master:/content/home
$item.Image = get-item "master:/media library/Showcase/cognifide_logo"
@AdamNaj
AdamNaj / Renderings.ps1
Created June 23, 2014 16:19
Rendering manipulation in PowerShell for Sitecore
$item = get-item master:\content\Demo\Int\Home
$device =Get-Device -Default
$contentDataSource = get-item master:\content\Demo\Int\Home\about-us\employee-stories\adam-najmanowicz
$ImageDataSource = get-item master:\content\Demo\Int\Data\Images\d56cf7e777a2496aa6489a7bffc03539
$rendering = get-item master:\layout\Sublayouts\ZenGarden\Basic\Content
Add-Rendering -Item $item -Device $device -Rendering $rendering -Placeholder main -Parameter @{FieldName ="Title"} -DataSource $contentDataSource
$rendering = get-item master:\layout\Sublayouts\ZenGarden\Basic\Image
Add-Rendering -Item $item -Device $device -Rendering $rendering -Placeholder main -DataSource $ImageDataSource
$rendering = get-item master:\layout\Sublayouts\ZenGarden\Basic\Subtitle
Import-Function Resolve-Error
#Show-FieldEditor -Item (gi master:\content\cognifidecom\int\settings) -PreserveSections -Width 500 -Height 500 -title "Zen Garden Site settings"
$content = gi master:\layout\Sublayouts\ZenGarden\Basic\Content | New-Rendering -Placeholder "main"
$item = gi master:\content\Demo\Int\Home
<#Add-Rendering -Item $item -PlaceHolder "main" -Rendering $content -Parameter @{ FieldName = "Content" }
Add-Rendering -Item $item -PlaceHolder "main" -Rendering $content -Parameter @{ FieldName = "SummaryText" }
Add-Rendering -Item $item -PlaceHolder "main" -Rendering $content -Parameter @{ FieldName = "SummaryIcon" }
#>
#$renderings = $item | Get-Rendering -Placeholder "main"
foreach ($rendering in $Renderings)
@AdamNaj
AdamNaj / CreateMissingDocFiles.ps1
Created July 14, 2014 11:35
Create Documentation templates
$DocumentationFolder = "C:\Projects\sitecorepowershell\Trunk\Documentation"
$documented = Get-ChildItem $DocumentationFolder | % { $_.BaseName }
$undocumented = get-command | ? { $_.DLL -match "Cognifide"} | ? { "$($_.Verb)-$($_.Noun)" -Notin $documented } | %{ "$($_.Verb)-$($_.Noun)" }
$undocumented | % {
$fileName = "$DocumentationFolder\$_.TODO.ps1"
if(Test-Path $fileName){
remove-item $filename
}
@AdamNaj
AdamNaj / install_package.ps1
Created July 25, 2014 15:30
Create Sitecore Install Package
# Clear test items:
# Get-ChildItem 'master:\system\Modules\PowerShell\Script Library' -recurse | Where-Object { ($_.Name -match '\(test\)') } | Remove-Item
$package = new-package "Sitecore PowerShell Extensions";
$package.Sources.Clear();
$package.Metadata.Author = "Adam Najmanowicz - Cognifide, Michael West";
$package.Metadata.Publisher = "Cognifide Limited";
$package.Metadata.Version = "2.6";
$package.Metadata.Readme = 'This module provides 2 immediately usable interfaces
@AdamNaj
AdamNaj / serialize_spe.ps1
Created July 25, 2014 15:49
Sitecore PowerShell Extensions - all involved item serialization
# Item templates
Get-Item 'master:\templates\Modules\PowerShell Console' | Serialize-Item -Recurse
Get-Item 'core:\templates\Modules\PowerShell Console' | Serialize-Item -Recurse
# Module Root
Get-Item 'master:\system\Modules\PowerShell' | Serialize-Item
Get-Item 'core:\system\Modules\PowerShell' | Serialize-Item
# Colors
Get-Item 'master:\system\Modules\PowerShell\Console Colors' | Serialize-Item -Recurse
$items = Get-Command * -CommandType Cmdlet | ? {$_.ModuleName -eq "" } | %{ Get-Help -Name ($_.Name) } | sort-object name
$props = @{
InfoTitle = "Sitecore PowerShell Commands"
InfoDescription = "Lists the sitecore power shell commands"
PageSize = 25
}
$items | Show-ListView @props -Property @{Label="Name"; Expression={$_.Name} }, @{Label="Synopsis"; Expression={$_.Synopsis} }