Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@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 / 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)"
}
}
[environment]::GetEnvironmentVariable("JAVA_HOME")
[environment]::GetEnvironmentVariable("SOLR_HOME")
@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)
@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 / Copy-ToRemote.ps1
Last active July 25, 2019 16:29
This copies a local file to the remote machine using PowerShell remote session with credentials provided
$pass = ConvertTo-SecureString -AsPlainText '123' -Force # 123 - actual password
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList 'Martin',$pass # Martin - actual username
$Session = New-PSSession -ComputerName 192.168.173.14 -Credential $Cred # IP address of remote machine
$remotePath = Invoke-Command -Session $session -ScriptBlock { New-Item -ItemType Directory -Force -Path Sifon } #Get-Location
Copy-Item -Path "c:\Some\Path\To\Local\Script.ps1" -Destination $remotePath.FullName -ToSession $session
Remove-PSSession $Session
@MartinMiles
MartinMiles / Execute-Remote.ps1
Last active July 25, 2019 16:29
This is a sample of WinRm code execution in a context of remote machine
$pass = ConvertTo-SecureString -AsPlainText '123' -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList 'Martin',$pass
Invoke-Command -ComputerName 192.168.173.14 -ScriptBlock { Get-ChildItem C:\ } -credential $Cred
@MartinMiles
MartinMiles / Install-Solr.ps1
Created April 15, 2019 07:13
This script installs Solr as service, downloads Java if required, creates certificates and patches solr.in.cmd for SSL
Param(
$installFolder = "c:\solr",
$solrPort = "8721",
$solrHost = "solr",
$solrSSL = $true,
$downloadFolder = "$PSScriptRoot"
)
$solrVersion = "7.2.1"
$solrName = "solr-$solrVersion"
@MartinMiles
MartinMiles / ExpanderCollapser.js
Created April 8, 2019 11:37
Adding Expand / Collapse buttons to Experience Editor (Sitecore 9)
/* Adds Expand all and Collapse all buttons to Content Editor */
scContentEditor.prototype.onDomReady = function (evt) {
this.addCollapser(window.jQuery || window.$sc);
};
scContentEditor.prototype.addCollapser = function ($) {
$ = $ || window.jQuery || window.$sc;
if (!$) { return; }
#Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false
#Set-ExecutionPolicy "RemoteSigned" -Scope CurrentUser -Confirm:$false
Set-ExecutionPolicy Unrestricted
Import-Module -Name SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://platform.dev.local
Invoke-RemoteScript -ScriptBlock {