Skip to content

Instantly share code, notes, and snippets.

#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"
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} }
@AdamNaj
AdamNaj / Available-Fields.ps1
Last active August 29, 2015 14:14
Find-Item test scripts
Find-Item -Index sitecore_master_index `
-Criteria @{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/system/modules/PowerShell/" } `
-First 1 |
select -expand "Fields"
@AdamNaj
AdamNaj / Test-WhatIf.ps1
Last active August 29, 2015 14:16
-WhatIf
$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 August 29, 2015 14:17
Zen Garden Release validator
$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;