Skip to content

Instantly share code, notes, and snippets.

View change_image_field.ps1
#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();
View new_update_image_field.ps1
$item = get-item master:/content/home
$item.Image = get-item "master:/media library/Showcase/cognifide_logo"
View rendering_playground.ps1
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 Jul 14, 2014
Create Documentation templates
View CreateMissingDocFiles.ps1
$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 / serialize_spe.ps1
Created Jul 25, 2014
Sitecore PowerShell Extensions - all involved item serialization
View serialize_spe.ps1
# 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
@AdamNaj
AdamNaj / install_package.ps1
Created Jul 25, 2014
Create Sitecore Install Package
View install_package.ps1
# 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
View get-psecommandshelp.ps1
$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} }
@AdamNaj
AdamNaj / Available-Fields.ps1
Last active Aug 29, 2015
Find-Item test scripts
View Available-Fields.ps1
Find-Item -Index sitecore_master_index `
-Criteria @{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/system/modules/PowerShell/" } `
-First 1 |
select -expand "Fields"
View Test-WhatIf.ps1
$item = get-item master:\content\Home\
$device = Get-LayoutDevice -Default
$layout = Get-Item "master:\layout\Layouts\Sample Layout"
$contentDataSource = get-item master:\content\home
$rendering = New-Rendering -Path "master:\layout\Renderings\Sample\Sample Rendering"
$renderingItem = Get-Item -Path "master:\layout\Renderings\Sample\Sample Rendering"
$blog = gi "master:/content/Home/blog";
$state = $blog | %{ $_."__Workflow state" }
New-ItemWorkflowEvent -Item $blog -Text "sdfasfd asdf sad fas" -OldState $state -NewState $state -WhatIf
@AdamNaj
AdamNaj / ZGReleaseValidator.ps1
Last active Aug 29, 2015
Zen Garden Release validator
View ZGReleaseValidator.ps1
$registered = [ordered]@{};
function Get-AttributeValue($attribute, $default){
@{$true="$default";$false=$attribute}[[string]::IsNullOrEmpty($attribute)];
}
function Is-Excluded($item, $excluded){
if($excluded.ContainsKey($item.Paths.Path)){
Write-Host "Excluded item: $($item.ProviderPath)" -ForegroundColor DarkCyan;
return $true;
You can’t perform that action at this time.