I'm trying to get my feet wet in Sitecore Powershell. I need to list renderings on a list of items. Some of the script works, like getting the items and outputting the name, but when calling Get-Rendering or Get-LayoutDevice i always get the error:

Current Sitecore database cannot be established, current location is not within a Sitecore content tree.

Google offers no help. What am I doing wrong? The script I am buildling on currently looks like this:

$pages = get-item master:/content/MySite/articles | get-childitem -Recurse | where-object { $_.TemplateName -match "Article" }
$device = Get-LayoutDevice -Default

foreach($page in $pages){
    write-host $page.name
    Get-Rendering -Item $page -Device $device    
  • That script seems to work fine on a fresh Sitecore 8.2. Are you logged in as admin? What version of Sitecore & Powershell are you running? Nov 15, 2016 at 11:21
  • Using Sitecore.NET 8.1 (rev. 151207) and Powershell 4.1 Nov 15, 2016 at 11:27
  • Cool - are you running it in the Powershell console? If so - what's before the cursor? (Should be something like "PS master:\>") Nov 15, 2016 at 11:30

1 Answer 1


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-Location master:

You can also set the context from the ISE window from the ribbon:

ISE Set Context

This was raised as an issue on Github and has been fixed in SPE 4.2 so that the context falls back to /sitecore/content instead.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.