Sitecore PowerShell : Part 3

 Sitecore PowerShell Examples:

Task 1: PowerShell Script which will show the report of Selected Item i.e. Item Name, Children, Language, Version, Id, Template Name etc.

Script:

$sampleItemTemplateId = "Item ID”

$sampleItemTemplateItem = Get-Item -Path "master: Item Path " -ID $sampleItemTemplateId

Get-ItemReferrer -Item $sampleItemTemplateItem

Output:



Task 2: PowerShell Script which will show the report of Item child i.e. Child Name, Children, Language, Version, Id, Template Name

Script:

Method 1:

Get-ChildItem -Path master: Item Path -Recurse| Where-Object { $_.TemplateName -ne "Page"}

Output:



Method 2: To Find Data for Selected Language.

$path = "master: Item Path "

@(Get-Item -Path $path -Language "en*" -Version *) + @(Get-ChildItem -Path $path -Language "en*"  -Version * -Recurse)

Output:


Task 3: PowerShell Script Export Sitecore data into excel

Script:

Method 1:

Import-Function -Name ConvertTo-Xlsx

[byte[]]$outobject = Get-ChildItem master: Item Path |

    Select-Object -Property Name, ProviderPath, id, Language, Varsion, Content |

    ConvertTo-Xlsx

Out-Download -Name "report-$datetime.xlsx" -InputObject $outobject

 Output:


Method 2:

Import-Function -Name ConvertTo-Xlsx

 [byte[]] $data= Get-Item -Path master: -ID "Item Id" | Select-Object -Property Title,Content , TemplateName | ConvertTo-Xlsx

Out-Download -Name ReferrerInfo.xlsx -InputObject $data

Output:


Task 4: PowerShell Script to Update the item fields/content

Script:

$item = Get-Item -Path master: -ID "Item Id"

$item.Editing.BeginEdit()

$item.Fields["Title"].Value = "XYZ"

$item.Editing.EndEdit()

Output:

Before: 


Script Execution:


Result:


Task 5: PowerShell Script to Update the media reference

Script:

$item = Get-Item -Path "master: Item Path"

$item.Image = Get-Item -Path "master: Source Image Path

Output:

Before Execution:


Script Execution:

Result:


Task 6: PowerShell Script to find All Item Report/ Website Report

Script:

$itemList = Get-ChildItem "master: Item Path "

$reportProps = @{

    Title = "Report Title"

    InfoTitle = "This is a heading of the report."

    InfoDescription = "Total entries found: $($itemList.length)"

    PageSize = 25

}

$itemList | Show-ListView @reportProps -Property `

    @{ Label = "Item Name"; Expression = { $_.DisplayName } },

    @{ Label = "Path"; Expression = { $_.FullPath} }

Close-Window

Output:


Task 7: PowerShell Script to find all products that are active or Not

Script:

Method 1:

Get-Childitem master: Item Path |

   Where-Object { $_.Active -ne "1" } |

    Format-Table # or do something with them

Output:


Method 2:

Get-Childitem master: Item Path -Recurse |

    Show-Listview -Property Name, ProviderPath, @{Label="Active"; Expression={$_.Active -eq "1" }}

           

 Output:


Task 8: PowerShell Script to Delete All Subitems Under Items

Script:

$folderItem = Get-Item -Path 'master: Item Path'

Get-ChildItem -Path $folderItem.FullPath |

    ForEach-Object {  

            Write-Host "Deleting: " $_.Name

            $_ | Remove-Item -Recurse

        }               

Write-Host "Done"

Output:


Task 9: PowerShell Script to Delete All Folder with Subitems Under Item

Script:

Method 1: gci -path 'Item ID' -recurse | ri

        or

Method 2: gci -path 'Item ID' | ri -recurse

Task 10: PowerShell Script to Delete Subitem from Particular Template

Script:

gci -path ‘Item Path’ | where-object{$_.'Templateid' -eq 'Template Id'} | ri

 

 Note: More Read About Sitecore PowerShell Follow Part 1 & 2

Part 1Sitecore PowerShell : Part 1

Part 2Sitecore PowerShell : Part 2

Thanks For Reading My Blogs

You Can Also Continue Your Learning By Reading These More Blogs - 

Comments

Read More Blogs Here....

Sitecore JavaScript Services

LaMDA Software

Component In Sitecore / Create One Column Component In Sitecore:

Blockchain Technology

Sitecore PowerShell : Part 1

Contact Me/Any Suggestion

Name

Email *

Message *