Skip to content

Instantly share code, notes, and snippets.

View tackme31's full-sized avatar

tackme tackme31

View GitHub Profile
@tackme31
tackme31 / show-form-data.ps1
Last active December 14, 2020 05:51
A Sitecore PowerShell Extensions script for displaying data of Sitecore Forms without exporting.
<#
You can use this script as reporting tool by using Forms Data Viewer
- [Forms Data Viewer - Sitecore Marketplace](https://marketplace.sitecore.net/Modules/F/Forms_Data_Viewer.aspx)
#>
$result = Read-Variable -Parameters `
@{Name='formItem'; Title='Form'; Editor='droptree'; Source="DataSource=/sitecore/Forms"},
@{Name='startDate'; Title='Start date'; Editor='date'},
@{Name='endDate'; Title='End date'; Editor='date'}
@tackme31
tackme31 / rename-props.ps1
Last active February 24, 2020 05:38
Rename a property name of an object in PowerShell
$obj = [PSCustomObject]@{
Foo = "foo value"
Bar = "bar value"
Baz = "baz value"
}
$hogeProp = @{
Name = "Hoge"
Expression = {
return $_.Foo
@tackme31
tackme31 / update-licenses.ps1
Created July 9, 2019 04:42
A PowerShell script for updating the licenses of Sitecore 9.x
#Requires -RunAsAdministrator
param (
[Parameter(Mandatory=$true)]
[string]
$SitePrefix,
[Parameter(Mandatory=$false)]
[string]
$LicensePath = "$PSScriptRoot/license.xml",
[switch]
$WhatIf
@tackme31
tackme31 / GqlQuery.jsx
Last active July 9, 2019 05:04
A React component and its sample for querying GraphQL API with the dynamic variables. (for Sitecore JavaScript Service)
import React from 'react';
import { Query } from 'react-apollo';
import {
withSitecoreContext,
resetExperienceEditorChromes
} from '@sitecore-jss/sitecore-jss-react';
class GqlQuery extends React.Component {
render() {
const { query, sitecoreContext, rendering } = this.props;
@tackme31
tackme31 / compare-htmls.ps1
Created July 9, 2019 05:10
A PowerShell script for comparing the HTMLs fetched by Invoke-WebRequest
function Get-HtmlContent($url)
{
Invoke-WebRequest $url `
| select -ExpandProperty Content `
| % {$_.Split([Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries)}
}
$html1 = Get-HtmlContent "https://foo.example.com"
$html2 = Get-HtmlContent "https://bar.example.com"
@tackme31
tackme31 / update-thumbprints.ps1
Created July 24, 2019 07:29
A PowerShell script for updating the thumbprint of the xConnect certification in Sitecore 9.x
#Requires -RunAsAdministrator
param (
[Parameter(Mandatory=$true)]
[string]
$SitePrefix,
[Parameter(Mandatory=$true)]
[string]
$PfxFileOrThumbprint
)
@tackme31
tackme31 / compare-items.ps1
Created July 26, 2019 07:25
A Sitecore PowerShell Extensions script for comparison the fields of items.
$resultTypes = [ordered]@{
"Show all" = 1
"Only matched" = 2
"Only unmatched" = 4
}
function Get-ItemTitle {
param (
[Sitecore.Data.Items.Item]$Item
)
@tackme31
tackme31 / search-non-default-items.ps1
Last active March 20, 2020 15:10
A Sitecore PowerShell Extensions script for searching items with non-default value in the field.
$readVariableParams = @{
Parameters = @(
@{Name="root"; Title="Root item"; Editor="droptree"; }
@{Name="template"; Title="Template"; Editor="droptree"; Source="DataSource=/sitecore/templates" }
@{Name="fieldname"; Title="Field name" }
)
Title = "Search Edited Items"
Description = "Search items with non-default value in the field."
}
@tackme31
tackme31 / web.config
Created October 18, 2019 16:01
A configuration for setting a custom error page to Sitecore when a 404, 50x error occurs.
<!-- Add the following section to your web.config -->
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="502" subStatusCode="-1" />
<!-- Response the not found page (without changing a URL) -->
<error statusCode="404" prefixLanguageFilePath="" path="/notfound" responseMode="ExecuteURL"/>
<!-- Redirect to the static error page -->
<error statusCode="500" prefixLanguageFilePath="" path="/error.html" responseMode="Redirect"/>
@tackme31
tackme31 / CustomDocumentBuilder.cs
Created October 18, 2019 16:14
A sample code for adding a custom field to a Solr index dynamically.
public class CustomDocumentBuilder : SolrDocumentBuilder
{
public CustomDocumentBuilder(IIndexable indexable, IProviderUpdateContext context) : base(indexable, context)
{
}
protected override IEnumerable<IIndexableDataField> GetFieldsByItemList(IIndexable indexable)
{
var fields = base.GetFieldsByItemList(indexable);