Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
Last active August 29, 2017 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamNaj/8680921177c338e210f90bd538a7c917 to your computer and use it in GitHub Desktop.
Save AdamNaj/8680921177c338e210f90bd538a7c917 to your computer and use it in GitHub Desktop.
Copy or Move renderings from one device to another (within Shared layout)
#branch that should be replaced - change the path
$items = Get-ChildItem master:\content\home2 -WithParent
#Provide the names for your devices from which and to which things should be copied
$fromDevice = Get-LayoutDevice "Default"
$toDevice = Get-LayoutDevice "Mobile"
# for Final layout renderings you need to add -FinalLayout switch to the Add/Remove-Rendering cmdlets
# and provide the -Language for which you want to perform the operation
foreach($item in $items){
#get renderings from the source device
$renderings = @() + (Get-Rendering -Item $item -Device $fromDevice)
#wipe the target device before we copy the renderings - only if there is anything to copy
if($renderings.Count -gt 0){
Get-Rendering -Item $item -Device $toDevice |
% { Remove-Rendering -Item $item -Instance $_ -Device $toDevice }
}
foreach($rendering in $renderings){
# uncomment the next line if you want to remove from the existing device
# Remove-Rendering -Item $item -Instance $rendering -Device $fromDevice
#let's assign the new Unique ID in case you don't want to remove the previous one
$rendering.UniqueId = [Guid]::NewGuid();
#add to teh new device from the previous device
Add-Rendering -Item $item -Instance $rendering -Device $toDevice -PlaceHolder $rendering.PlaceHolder
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment