44
votes
Accepted
How can I programmatically add a rendering to all of my content items?
You can do this by using the Powershell Extensions module.
$item = get-item master:\content\Demo\Int\Home
$device =Get-Device -Default
$contentDataSource = get-item master:\content\Demo\Int\Home\...
23
votes
How can I programmatically add a rendering to all of my content items?
Another option is to use the Sitecore search bulk update actions.
Start a search at the root of your content tree (e.g. /sitecore/content/home).
Click on the little magnifying glass
Enter a search ...
22
votes
Accepted
Deleting an Item with a null Template
A safer method would be to use the DbBrowser. You can find this by going to <yoursiteurl>/sitecore/admin/dbbrowser.aspx. You will get a screen where the content tree loads up on the left and you ...
21
votes
Accepted
Sitecore Powershell query for big images of a certain size
August 2019 Update
There is a report included with SPE allowing you to find images by a specific size.
January 2018 Update - 6 months later
So we've added a few more websites with media to our ...
20
votes
Accepted
How to check an item exists with powershell without raising an error?
Try this
$database = "master"
$homeItem = "$($database):\sitecore\content\home123"
$homeExists = Test-Path -Path $homeItem
19
votes
Powershell get all items that use a template
There is a report included with SPE called Items with Template that can provide you with this information. This report scans a tree and checks for inheritance at any level. Slow because it has to look ...
16
votes
Accepted
Copy final layout to shared layout
I wrote a PowerShell cmldet for merging Final Renderings back into Shared Renderings.
function Merge-Layout {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true,Position = 0,...
16
votes
Accepted
Issue elevating SPE Console in 9.1 Azure PaaS
I recently discovered this issue on my local instance of SPE while working on 5.1. Corey Smith showed me how to resolve this issue as it recently came up with Unicorn.
Apply the following patch for ...
14
votes
Accepted
Create new language version for content branch
There is already one blog post on this topic on Internet
Code snippet from the blog as below:
Add-ItemLanguage -Path "master:\sitecore\content" -Language "en" -TargetLanguage "de-DE" -IfExist ...
14
votes
Accepted
Can you run Sitecore Powershell without triggering Sitecore events?
This is how you could use the using statement inside Powershell
function Using-Object
{
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[...
14
votes
Accepted
Update all users in the Administrator Role
In SPE you should be able to do the following to get a list of all users with the admin role.
This should get you users, with admin role who are not the default admin
$users = Get-User -Filter*
...
14
votes
Sitecore PowerShell extensions module compatibility with Sitecore 9.2
I do know that I personally built 5.1 to address the compatibility issue with jobs.
I encourage you to consider trying that to confirm it corrects the issue.
https://github.com/SitecorePowerShell/...
13
votes
Accepted
How to create Sitecore Context Item to copy Item Path using SPE?
I wouldn't use Sitecore Powershell Extensions for this. SPE doesn't have anything for interacting with the clipboard and also doesn't execute custom JS from scripts (yet!).
Additionally, there ...
13
votes
Accepted
Sitecore Powershell Script to find all the items with Personalizations defined
If personalisation is enabled for an item, then there will be a parameter named rules, when we get the rendering using "Get-Rendering". The same can be done for a parent item and run the code for ...
13
votes
Accepted
Using Powershell Extensions to remove empty <p> tags from all rich text fields
You can use the below script to remove all empty p/P tags (having space or ).
This script uses the HtmlDecode method of System.Web.HttpUtility class to decode single or multiple ...
12
votes
Accepted
Update same rendering of several templates using SPE
Quick test confirms that the following allows you to set a rendering parameter on existing items.
# Path to the Coveo rendering you need to update
$rendering = Get-Item "master:\sitecore\layout\...
12
votes
How to check an item exists with powershell without raising an error?
An alternative would be to run the Get-Item command and provide the necessary ErrorAction parameter to hide the output.
# Variable $item will contain the object if found.
if(($item = Get-Item -Path "...
12
votes
Accepted
SPE to Unlock all items locked by a specific user
Something like that should do the trick:
Get-ChildItem master:\content -rec |
Where-Object { $_.Locking.GetOwner() -eq "sitecore\USERNAME" } |
% { $_.Locking.Unlock() }
You just take all the ...
11
votes
Accepted
How to reset DisplayName to empty using Sitecore PowerShell Extensions?
You can use this to set it to empty. With this you don't need to wrap the change with BeginEdit and EndEdit
$item."__Display Name" = ""
You only need the quotes here as there is a space in the name,...
11
votes
Accepted
Getting "Current Sitecore database cannot be established" using Sitecore Powershell Extensions
SPE loses Sitecore context if /sitecore/content/home item is not present and falls back to Windows context.
To force it to use the master database set the location at the top of your script:
Set-...
11
votes
Accepted
Compare item versions with Sitecore PowerShell Extension
I found some code from John West some time back and made that into a module on Github.
You could take the below snippet I converted to PowerShell and make it a report.
# Create a list of field names ...
11
votes
How to hide ribbon in Sitecore
You can use Sitecore Contextual Ribbon to do the above task. You will not require to do any code implementation.
You need to create the ribbon in Core database at the path /sitecore/content/...
11
votes
Accepted
SPE How to add multiple items to package source
The script we use to bundle up SPE can be found here:
/sitecore/system/Modules/PowerShell/Script Library/Platform/Development/PowerShell Extensions Maintenance/Prepare Console Distribution.
From the ...
11
votes
Accepted
Powershell get all items that use a template
This should do it for you.
$defaultPath = "/sitecore/content"
[Sitecore.Data.ID]$articleId = "{03360FC1-B4C0-4770-9E1D-79E8317B74DD}"
$articles = Find-Item -Index sitecore_master_index `
-Where '...
10
votes
Accepted
How to get list of all the renderings that has been configured to use data source
Based on your question I think you need something that will require a bit more finesse, so here's my attempt - It will only show renderings that have no datasource, but need them
function Test-...
10
votes
Updating Workflow for all the Items in Sitecore Instance
You can use below powershell script (https://gist.github.com/marcduiker/950e0358bb4752ed5b047931a8c958c1) :
# This is the ID of the workflow that will be set on the content items.
$script:...
9
votes
Accepted
PowerShell ISE: Function of Abort button?
After currently executing "line of code" will finish its job then script execution will be immediately suspended once you click Abort.
So you don't have to control execution by your own. What is ...
9
votes
Can you run Sitecore Powershell without triggering Sitecore events?
Wrapping your code in a BulkUpdateContext block as mentioned in the Powershell GitBook will make the tasks more performant and also silence any events or tasks.
Import-Function -Name New-UsingBlock
...
9
votes
Accepted
Where should I install Powershell module for SXA?
SPE is only required for environments that use the Sitecore interface. If you are going to use the Content Editor or Experience Editor then install the module.
Essentially only the CM needs SPE.
9
votes
Accepted
Set Powershell script language
You can set context language using
Syntax:
#get language to be switched
$lan = [Sitecore.Globalization.Language]::Parse("$switchLanguage")
#Set Context language, use 'ispersistent' parameter ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
powershell-extensions × 453powershell × 67
sxa × 22
sitecore-client × 13
media-library × 13
sitecore-api × 10
presentation × 9
content-editor × 7
workflow × 6
publishing × 5
security × 5
scheduled-tasks × 5
sitecore-commerce × 4
installation × 4
templates × 4
sitecore-query × 4
content-migration × 4
azure × 3
sitecore-install-framework × 3
packages × 3
events × 3
tree-list × 3
xdb × 2
content-search × 2
jss × 2