0

I have got

$eventsPath = "/sitecore/content/Global Content/Events"
$templateId = "{EBE88C21-4035-4266-9647-B4C88F1BC000}"

# Function to get data and print on the screen
function Print-EventData($item) {
    $nId = $item.ID
    $title = $item.Name
    
    $created = $item.Statistics.Created
    $changed = $item.Statistics.Updated
    
    $eventDetails = $item.PSFields.'Event Title'.value
   #image

    $imagePath = $item.PsFields.'image'.value
    
    #searchTags
    $searchTags = $item.PsFields.'Search Tags'.GetItems() | ForEach-Object { $_.DisplayName }
    $searchTagsString = if ($searchTags) { $searchTags -join '|' } else { "NA" }

    #field_domain_acess
    $relatedSiteDetails = $item.PsFields.'Related Site'.GetItems() | ForEach-Object { $_.DisplayName }
    $relatedSite = if ($relatedSiteDetails) { $relatedSiteDetails -join '|' } else { "NA" }

    #field_event_catogery
    $eventCategory =  $item.PsFields.'Event Category'.GetItems() | ForEach-Object { $_.DisplayName }
    $eventCategoryString =  if ($eventCategory) { $eventCategory -join '|' } else { "NA" }
   

   
 
   
   
   
   
   
    #Write-Host "$relatedSiteDetails"
    Write-Host "Item ID:$nId , title = $title , Created: $created, changed: $changed, Image Path: $imagePath, Searchtags: $searchTagsString, field_domain_acess: $relatedSite "
}

# Get the root item
$rootItem = Get-Item -Path $eventsPath

# Process the root item and its children
foreach ($item in Get-ChildItem -Path $rootItem.FullPath -Recurse) {
    if ($item.TemplateID -eq $templateId) {
        Print-EventData -item $item
    }
}

how can I get the equivalent result in master index using Find-Item

2 Answers 2

0

You can get it by following script.

$eventsPath = "/sitecore/content/Global Content/Events"
$eventsItem = Get-Item -Path $eventsPath
$templateId = [ID]::Parse("{EBE88C21-4035-4266-9647-B4C88F1BC000}")

$props = @{
    Index = "sitecore_master_index"
    Where = 'TemplateId = @0 And Paths.Contains(@1)'
    WhereValues = $templateId, $eventsItem.Id
}

Find-Item @props

Do checkout examples on this page for any modification - https://doc.sitecorepowershell.com/appendix/indexing/find-item

0

Following are a few parameters that we can use with Find-Item:

  • Index: Where we specify the name of the index to use.
  • Criteria: Where we specify the Search Filter
  • First: Where we can specify the number of results to return
  • Skip: Where we can specify the number of results to be skipped before returning the result
  • Where: Where we can specify Dynamic Linq to filter results
  • WhereValue: Where we can specify Array of values that will be used by -Where Linq statement

Here is one example, you can use.

$FilterCriteria = @(
    @{Filter = "Equals"; Field = "_templatename"; Value = "Event Details"},
    @{Filter = "StartsWith"; Field = "_fullpath"; Value = "/sitecore/content/Events" }
)
Find-Item -Index "sitecore_master_index" -Criteria $FilterCriteria

Every Filter has three imp parts: Field, Filter, and Value.

  • Filter: Where we specify the operator for evaluating the condition. Ex- -
  • Equals, StartsWith, Contains, EndsWith, LessThan, GreaterThan etc.
  • Field: Where we can specify the name of the indexed field that we want to use in filtering condition. Value: Value of the field for satisfying the condition.

Hope this helps.

Your Answer

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

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