Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@MartinMiles
MartinMiles / Check-NetCore.ps1
Created September 16, 2019 18:46
Verifies if .NET Core is installed on the machine
$DotNETCoreUpdatesPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET Core"
$DotNetCoreItems = Get-Item -ErrorAction Stop -Path $DotNETCoreUpdatesPath
$NotInstalled = $True
$DotNetCoreItems.GetSubKeyNames() | Where { $_ -Match "Microsoft .NET Core.*Windows Server Hosting" } | ForEach-Object {
$NotInstalled = $False
Write-Host "The host has installed $_"
}
If ($NotInstalled) {
Write-Host "Can not find ASP.NET Core installed on the host"
}
@MartinMiles
MartinMiles / ClipboardFileTransfer.psm1
Created November 4, 2019 02:18
A helpful PowerShell module that lets you move (smallish) files over the clipboard - useful when you have RDP access to a machine but are not allowed to share drives.
function Write-EmbeddedFile
{
param
(
[string]$base64,
[string]$targetFile
)
process
{
$Content = [System.Convert]::FromBase64String($base64)
[environment]::GetEnvironmentVariable("JAVA_HOME")
[environment]::GetEnvironmentVariable("SOLR_HOME")
@MartinMiles
MartinMiles / Get-SitecoreInstances.ps1
Created November 5, 2019 04:24
Sitecore Instances List
Get-WebSite | ForEach-Object {
$binPath = Join-Path -Path $_.PhysicalPath -ChildPath "bin\Sitecore.Kernel.dll"
$item = Get-Item -Path $binPath -ErrorAction SilentlyContinue
if( $item -ne $null )
{
"Sitecore Site: Name:$($_.Name), Version: $($item.VersionInfo.FileVersion), Path $($_.PhysicalPath)"
}
}
@MartinMiles
MartinMiles / Get-SitecoreServices.ps1
Created November 5, 2019 04:25
Sitecore Services List
Write-Host "SQL" -ForegroundColor Green
Get-Service *SQL*
Write-Host "SOLR" -ForegroundColor Green
Get-Service *solr*
(gwmi win32_service|?\{$_.name -like "*solr*"}).pathname
Write-Host "Mongo" -ForegroundColor Green
Get-Service *mongo*
(gwmi win32_service|?{$_.name -like "*mongo*"}).pathname
@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) {
@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 / 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 / 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 / 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`