Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
AdamNaj / Find-MostExecutedSolrQuery.ps1
Last active June 2, 2024 18:34
Most executed Solr queries from latest Sitecore logs
# Gets the latest 30 log files, filters only solr query lines from them, groups them by query content and orders by most executed,
# Letting you find things that are most effective to cache.
Set-HostProperty -HostWidth 2000
$logFileFilter = "azure.log.*"
$logfileCountToAnalyse = 30
$minQueryOccurence = 20
Get-ChildItem $SitecoreLogFolder -Recurse -Filter $logFileFilter `
@ericchansen
ericchansen / monitor_usb.ps1
Created May 24, 2023 18:19
PowerShell script to monitor device connects and disconnects on Windows.
$CurrentState = $null
$NewState = $null
Write-Host "Monitoring device changes..." -ForegroundColor Green
while ($true) {
if (-not($CurrentState)) {
$CurrentState = Get-PnpDevice -Status OK
}
else {
$NewState = Get-PnpDevice -Status OK
$Changes = $null
$datasource = Get-Item .
$referrers = $datasource | Get-ItemReferrer
$pageOnlyReferrers = $referrers | Where-Object { $_.Name -ne '__Standard Values' } | Sort-Object -Property Name -Unique
$pageOnlyReferrers = $pageOnlyReferrers | Where-Object { $_.Paths.Path -like '/sitecore/content/{site-node}' }
if ($pageOnlyReferrers.Count -eq 0) {
return;
}
@georgechang
georgechang / death.scriban
Last active February 10, 2023 18:01
This is why we can't have nice things
{{
# Get all pages that are nested under the root
# Check if it has a layout (avoids data source object)
# Set flag to true. Show everything if no filter is set.
# Get page filters. If a section has filters, set taxonomy flag to false. At least one field must match selected filters. Set to true #if we find a matching field.
# If the field parsing remains true after checking each field, add the item to an array.
# The array takes the item, and the date field parsed to that the date is a single number, year/month/day.
# After all field and array parsing is done, sort the array by date.
# Loop through the array and render the items.
@michaellwest
michaellwest / PullAllDockerImages.ps1
Last active September 1, 2023 01:28
A convenient PowerShell script to list all the docker images and pull the from the registry.
docker image ls --format "{{json .Repository}},{{json .Tag}},{{json .ID}}" |
ConvertFrom-Csv -Header "Repository","Tag","Id" |
Where-Object { $_.Tag -ne "<none>" -and $_.Repository.Contains("/") } |
ForEach-Object { docker pull "$($_.Repository):$($_.Tag)"}
@peplau
peplau / SPE: Quick Download Tree as Package (Advanced)
Last active November 10, 2022 20:39
SPE: Advanced Quick Download Tree as Package - Allows the user to pick and choose among Linked Items to include in the package as well
Line 1 - Changed the Import-Function Name to Setup-PackageGeneratorAdvanced
Line 5 - Removed as the $path variable was not used
Lines 20-22 - Updated to always show the Links tab, which is now a radiobox
Line 74 - Replaced by the block from lines 75 to 149
Lines 76 to 87 - Replaced by the block from lines 151 to 162
@ErikNoren
ErikNoren / Program.cs
Last active May 11, 2024 20:26
ASP.NET Core 6 configuration settings stored in a SQL database and acts just like appsettings.json
//Snippet from Program.cs which adds the provider and sets up a Settings class to map the settings
using ErikNoren.Configuration;
using TestMvcWebApplication;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddSqlDatabase(config =>
{
//We can get the connection string from previously added ConfigurationProviders to use in setting this up
config.ConnectionString = builder.Configuration.GetConnectionString("DemoDatabase");
@michaellwest
michaellwest / FindRevisionIssues.ps1
Last active May 2, 2024 14:17
Sitecore PowerShell Extensions script to rename items. Workaround for an issue in SXA where items are not published because the revision is missing on the item (even though the Content Editor shows one). Sitecore Support public reference number 522438
$matchedItems = [System.Collections.ArrayList]@()
$revisionFilter = @("9323dec0-9b37-4fae-b87c-2dc12cbea0f2")
Get-ChildItem -Path "master:\media library" -Recurse |
Where-Object { [string]::IsNullOrEmpty($PSItem["__revision"]) -or $revisionFilter -contains $PSItem["__revision"] } |
ForEach-Object { $matchedItems.Add([PSCustomObject]@{"ItemId"=$PSItem.ID; "RevisionId"=$PSItem["__revision"]; "ItemPath"=$PSItem.ItemPath}) > $null }
$matchedItems | Show-ListView
@rminderhoud
rminderhoud / powershell-web-server.ps1
Last active June 3, 2024 11:39 — forked from 19WAS85/powershell-web-server.ps1
A simple web server built with powershell.
# This is a super **SIMPLE** example of how to create a very basic powershell webserver
# 2019-05-18 UPDATE — Created by me and and evalued by @jakobii and the comunity.
# Http Server
$http = [System.Net.HttpListener]::new()
# Hostname and port to listen on
$http.Prefixes.Add("http://localhost:8080/")
# Start the Http Server
@cassidydotdk
cassidydotdk / Build.ps1
Last active May 23, 2021 06:01
Complete Build and Publish Script. Will deploy all projects to publishing target, no HPP required.
param(
[Parameter()]
[switch]$NoBuild,
[Parameter()]
[switch]$NoSync,
[Parameter()]
[string]$CmHost="https://habitatstarterkit.local",
[Parameter()]
[string]$SolutionName="HabitatStarterKit.sln",
[Parameter()]