Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@MartinMiles
MartinMiles / ConvertTo-PublishingModuleWdp.ps1
Last active January 24, 2021 02:07
his scripts uses SAT for converting a Sitecore Publishing Module into a WebDeploy package to deploy into Azure PaaS
# Usage:
# .\ConvertTo-PublishingModuleWdp.ps1 -SitecoreAzureToolkitRoot "C:\Sitecore\SAT" -Path "C:\Sitecore Publishing Module 3.1.4 rev. 200110.zip" -Destination "C:\output"
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateScript({ Test-Path $_ -PathType Container -IsValid })]
[string]$SitecoreAzureToolkitRoot,
[Parameter(Mandatory = $true)]
@MartinMiles
MartinMiles / ConvertTo-PublishingServiceWdp.ps1
Created January 22, 2021 21:51
This scripts creates a prepared Sitecore Publishing Service into a WebDeploy package to deploy into Azure PaaS
# Usage for this scrtip:
# .\ConvertTo-PublishingServiceWdp.ps1 -Path "C:\Sitecore Publishing Service 3.1.1 rev. 180807-x64.zip" -Destination "C:\output"
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[ValidateScript({ (Test-Path $_ -PathType Leaf) -and ($_ -match '\.zip$') })]
[string]$Path,
[Parameter(Mandatory=$true)]
@MartinMiles
MartinMiles / Replace-Content.ps1
Last active January 22, 2021 14:09
One-liner recursively replace content in files
gci -r -include "*.yml","*.xml" | foreach-object { $a = $_.fullname; ( get-content $a -Encoding UTF8) | foreach-object { $_ -replace "FROM VALUE","TO VALUE" } | set-content $a -Encoding UTF8}
@MartinMiles
MartinMiles / Re-attach-recreating-log-file.sql
Created January 18, 2021 21:47
Re-attach SQL database from an MDF file (good for detaching for removing huge LDF)
-- you should have you DB up& running (for example, after restoring)
-- then you need to detach the database and delete that huge .LDF file
-- it will get re-created upon re-attaching by using the below command
CREATE DATABASE databasename
ON (FILENAME= 'c:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\databasename_web.mdf')
FOR ATTACH_REBUILD_LOG
GO
@MartinMiles
MartinMiles / TestSitecorePowerShellRemoting.ps1
Last active February 10, 2021 15:46
SPE Remoting (1. Install Sitecore module; 2. Install remoting module into $PSHome\Modules; 3. Weaken security ie. ShieldsDown.config )
Set-ExecutionPolicy RemoteSigned
Import-Module -Name SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri https://platform
Invoke-RemoteScript -ScriptBlock {
Get-Item -Path "master:\content\Home"
} -Session $session
@MartinMiles
MartinMiles / RemoveDatabasesByPrefix.ps1
Created August 9, 2020 02:17
A PowerShell snippet to call SQL command to remove all DBs starting with 'Platform'
Invoke-Sqlcmd -ServerInstance "(local)" -Query "`
DECLARE @dbnames NVARCHAR(MAX) SET @dbnames = ''`
DECLARE @alter NVARCHAR(MAX) SET @alter = ''`
DECLARE @statement NVARCHAR(MAX) SET @statement = ''`
`
SELECT @dbnames = @dbnames + ',[' + name + ']' FROM sys.databases WHERE NAME LIKE 'Platform_%'`
SELECT @alter = @alter + 'ALTER DATABASE [' + name + '] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;' FROM sys.databases WHERE NAME LIKE 'Platform_%'`
IF LEN(@dbnames) > 0`
BEGIN`
EXEC sp_executesql @alter`
@MartinMiles
MartinMiles / Sitecore.ContentSearch.Solr.Index.Preview.config
Last active March 1, 2020 19:45
Preview index configuration, to be put under App_Config\Sitecore\ContentSearch folder along with other index definitions
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
<sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="solr">
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="sitecore_preview_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="core">DigitalEcosystem_preview_index</param>
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
@MartinMiles
MartinMiles / PreviewPublishingTarget.config
Last active March 1, 2020 19:47
The configuration for a preview publishing target database along with a site definition, to be put under App_Config\Include folder
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<!--
This configuration adds "preview" publishing target as a copy of production-like "web" database for Sitecore 9.3
Please refer to a full guide video for the usage instructions: https://youtu.be/...
WARNING!
This configuration is done for demo purposes only, do not use it as is.
@MartinMiles
MartinMiles / user.js
Last active December 22, 2019 03:19
Firefox user.js file I am using for privacy and performance (located at c:\Users\martin\AppData\Roaming\Mozilla\Firefox\Profiles or similar)
user_pref("browser.bookmarks.showMobileBookmarks", true);
user_pref("browser.ctrlTab.previews", true);
user_pref("browser.download.autohideButton", false);
user_pref("browser.download.panel.shown", true);
user_pref("browser.library.activity-stream.enabled", false);
user_pref("browser.newtabpage.activity-stream.feeds.places", true);
user_pref("browser.newtabpage.activity-stream.feeds.section.highlights", false);
user_pref("browser.newtabpage.activity-stream.feeds.telemetry", false);
user_pref("browser.newtabpage.activity-stream.filterAdult", false);
user_pref("browser.newtabpage.activity-stream.prerender", false);
@MartinMiles
MartinMiles / Install-SIF.ps1
Created November 21, 2019 15:48
Installs recent version of Sitecore Install Framework along with required dependencies
$SitecoreModuleName = 'SitecoreInstallFramework'
$SitecoreRepositoryUrl = 'https://sitecore.myget.org/F/sc-powershell/api/v2'
$SitecoreRepositoryName = 'SCGallery'
# Install NuGet package repository
Install-PackageProvider "NuGet" -MinimumVersion 2.8 -Force | Out-Null
# Install Sitecore's powershell gallery
$SCGallery = Get-PSRepository $SitecoreRepositoryName -ErrorAction SilentlyContinue
If ($null -eq $SCGallery) {