6

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? – Owen Niblock Nov 15 '16 at 11:21
  • Using Sitecore.NET 8.1 (rev. 151207) and Powershell 4.1 – Troels Aaberg Nov 15 '16 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:\>") – Owen Niblock Nov 15 '16 at 11:30
11

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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