-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nick's blog added to sample scripts: http://www.techphoria414.com/Blo…
…g/2012/March/Change-Item-Templates-With-Sitecore-PowerShell Read-Variable returned items are now wrapped with PowerShell extensions
- Loading branch information
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...es/PowerShell/Script Library/Examples/Content Maintenance/Mass Change Item Templates.item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
----item---- | ||
version: 1 | ||
id: {50456B81-0FB3-4705-BC61-E6FDD2CF98A3} | ||
database: master | ||
path: /sitecore/system/Modules/PowerShell/Script Library/Examples/Content Maintenance/Mass Change Item Templates | ||
parent: {F25BF203-F58F-4F3C-B017-3ACD2F063479} | ||
name: Mass Change Item Templates | ||
master: {00000000-0000-0000-0000-000000000000} | ||
template: {DD22F1B3-BD87-4DB2-9E7D-F7A496888D43} | ||
templatekey: PowerShell Script | ||
|
||
----version---- | ||
language: en | ||
version: 1 | ||
revision: 1b5da6d3-8bcd-4f41-ba0f-ce0b04c88320 | ||
|
||
----field---- | ||
field: {B1A94FF0-6897-47C0-9C51-AA6ACB80B1F0} | ||
name: Script | ||
key: script | ||
content-length: 1505 | ||
|
||
<# | ||
Based on Blog by @Techphoria414 - Nick Wesselman | ||
http://www.techphoria414.com/Blog/2012/March/Change-Item-Templates-With-Sitecore-PowerShell | ||
#> | ||
|
||
$sourceTemplate = get-item 'master:\templates\Sample\Sample Item' | ||
$targetTemplate = get-item 'master:\templates\Sample\Sample Item' | ||
$branch = get-item . | ||
$result = Read-Variable -Parameters ` | ||
@{ Name = "branch"; Title="Branch to work on"; Root="/sitecore/"; Tooltip="Items you want to work on."}, ` | ||
@{ Name = "sourceTemplate"; Title="Current template"; Root="/sitecore/templates/"; Tooltip="Template you want to replace."}, ` | ||
@{ Name = "targetTemplate"; Title="New template"; Root="/sitecore/templates/"; Tooltip="Template you want to use."} ` | ||
-Description "This report will replace template on all items in the tree with another template of your choice" ` | ||
-Title "Branch Template Replace" -Width 500 -Height 400 ` | ||
-OkButtonName "Replace" -CancelButtonName "Cancel" | ||
|
||
if($result -ne "ok") | ||
{ | ||
Exit | ||
} | ||
|
||
$path = $branch.ProviderPath; | ||
cd $branch.ProviderPath; | ||
$targetTemplateItem = New-Object -TypeName "Sitecore.Data.Items.TemplateItem" -ArgumentList $targetTemplate | ||
Write-Host "For branch '$($branch.ProviderPath)' changing templates from '$($sourceTemplate.Name)' to '$($targetTemplate.Name)'" | ||
Get-ChildItem $path -recurse | Where-Object{$_.TemplateID -eq $sourceTemplate.ID} | ForEach-Object { $_.ChangeTemplate($targetTemplateItem); Write-Host "Changing $($_.ProviderPath)" }; | ||
|
||
Show-Result -Text -Width 800 -Height 700 | ||
Close-Window | ||
----field---- | ||
field: {25BED78C-4957-4165-998A-CA1B52F67497} | ||
name: __Created | ||
key: __created | ||
content-length: 15 | ||
|
||
20130902T111843 | ||
----field---- | ||
field: {8CDC337E-A112-42FB-BBB4-4143751E123F} | ||
name: __Revision | ||
key: __revision | ||
content-length: 36 | ||
|
||
1b5da6d3-8bcd-4f41-ba0f-ce0b04c88320 | ||
----field---- | ||
field: {D9CF14B1-FA16-4BA6-9288-E8A174D4D522} | ||
name: __Updated | ||
key: __updated | ||
content-length: 34 | ||
|
||
20130902T111843:635137175234032422 | ||
----field---- | ||
field: {BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A} | ||
name: __Updated by | ||
key: __updated by | ||
content-length: 14 | ||
|
||
sitecore\admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters