Skip to content

Instantly share code, notes, and snippets.

@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-Dialogs.ps1
Last active December 5, 2016 14:28
Dialog Test Script
#Host Color test
$Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'White')
$Host.UI.RawUI.ForegroundColor = 'Black'
$Host.PrivateData.ErrorForegroundColor = 'Red'
$Host.PrivateData.ErrorBackgroundColor = $bckgrnd
$Host.PrivateData.WarningForegroundColor = 'Magenta'
$Host.PrivateData.WarningBackgroundColor = $bckgrnd
$Host.PrivateData.DebugForegroundColor = 'Blue'
$Host.PrivateData.DebugBackgroundColor = $bckgrnd
$Host.PrivateData.VerboseForegroundColor = 'Green'
@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;
@AdamNaj
AdamNaj / Add-ItemAccess.ps1
Created April 15, 2015 06:51
ACL Manipolation
function Add-ItemAccess{
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[Sitecore.Data.Items.Item]$item,
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$roleName)
@AdamNaj
AdamNaj / ExportAccountsInAPackage.ps1
Created May 25, 2015 21:29
Export Roles and users in a package
$package = (New-Package -Name "Security")
$source = Get-Role -Filter * | New-SecuritySource -Name "All Roles"
$package.Sources.Add($source)
$source = Get-User -Filter * | New-SecuritySource -Name "All Users"
$package.Sources.Add($source)
$source = New-SecuritySource -Filter sitecore\* -Name "Sitecore Roles and users" -AccountType Unknown
$package.Sources.Add($source)
Export-Package "Security" -Project $package
@AdamNaj
AdamNaj / Find-CmdletsWithLanguageParem.ps1
Created June 15, 2015 09:40
Find SPE cmdletsthat have Language Parameter
Get-Command -CommandType Cmdlet | ? { $_.DLL -match "Cognifide"} | ? { $_.Parameters.ContainsKey("Language")} | sort Name
@AdamNaj
AdamNaj / RV-Item-WithNoItemDefined.ps1
Created July 8, 2015 11:52
Read-Variable with no item pre-defined
Read-Variable -Parameters `
@{ Name = "item"; Title="Start Item"; Root="/sitecore/content/"; Editor="item"},
@{ Name = "items"; Title="Bunch of Templates";
Source="DataSource=/sitecore/templates&DatabaseName=master&IncludeTemplatesForDisplay=Node,Folder,Template,Template Folder&IncludeTemplatesForSelection=Template";
editor="treelist"},
@{ Name = "items2"; Title="Bunch of Templates";
Source="DataSource=/sitecore/templates&DatabaseName=master&IncludeTemplatesForDisplay=Node,Folder,Template,Template Folder&IncludeTemplatesForSelection=Template";
editor="multilist"; Height="230px"},
@{ Name = "items3"; Title="Pick One Template";
Source="DataSource=/sitecore/templates&DatabaseName=master&IncludeTemplatesForDisplay=Node,Folder,Template,Template Folder&IncludeTemplatesForSelection=Template";
@AdamNaj
AdamNaj / SpeRenderPercentageExample.ps1
Created July 25, 2015 13:24
Render Percentages report example
Import-Function Render-ReportField
1..100 | Show-ListView -Property @{Name="Value"; Expression={$_}}, @{Name="Percentage"; Expression={ Render-PercentValue $_}} `
-Title "percentages demo." `
-PageSize 200
@AdamNaj
AdamNaj / RichReport.ps1
Created July 27, 2015 09:12
Rich Reports
#Show-ListView - with rich renderers
Import-Function Render-ReportField
$script = Get-Item "master:\system\Modules\PowerShell\Script Library\Authorable Reports\Functions\Show-SearchResultDetails"
$index="sitecore_master_index"
Get-ChildItem master:\ | Show-ListView -Property `
ProviderPath, @{Label="Display Name"; Expression={ $_.DisplayName }},
HasChildren, TemplateName,
@{Label="Random Percent Test"; Expression={ Render-PercentValue (Get-Random -minimum 1 -maximum 100) }},
@{Label="Thumbnail"; Expression={ Render-ItemField $_ __thumbnail }},
@{Label="Index Fields"; Expression={ Render-ScriptInvoker $script @{index=$index; itemId="$($_.Uri)"} "Show Index Fields" } }