Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@MartinMiles
MartinMiles / Test-SQL.ps1
Last active April 1, 2019 17:51
PowerShell
Invoke-Sqlcmd -ServerInstance "." `
-Username "sa" `
-Password "SA_PASSWORD" `
-Query "SELECT GETDATE() AS TimeOfQuery"
(Get-Content Web.config).replace('<add key="role:define" value="ContentDelivery" />', '<add key="role:define" value="ContentDelivery" /><add key="localenv:define" value="PreProd" />') | Set-Content Web.config
@MartinMiles
MartinMiles / UploadFTP-File.ps1
Created April 1, 2019 19:10
Uploads local file to remote FTP from PowerShell
$File = "c:\Projects\output.zip"
$ftp = "ftp://erad-test-sitecore-615907-single\eradFTP:[email protected]/site/deployments/output.zip"
"ftp url: $ftp"
$webclient = New-Object System.Net.WebClient
#$uri = New-Object System.Uri($ftp)
$uri = [uri]::EscapeUriString($ftp)
stop-service solr6
get-childitem -path c:\Solr\6.6.2\server\solr\Platform*\Data -recurse | remove-item -force -recurse
start-service solr6
Restart-WebAppPool platform.dev.local
@MartinMiles
MartinMiles / TransformWithMsConfig.bat
Created April 8, 2019 11:33
That is how MsConfig performs config transformation
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe" /nologo /maxcpucount /nodeReuse:False /property:Configuration=Debug /property:Platform="Any CPU" /property:WebConfigToTransform=C:\inetpub\wwwroot\Platform.dev.local\ /property:TransformFile=C:\Projects\Platform.dev.local\src\Project\Careers\code\web.config.xdt /property:FileToTransform=web.config /target:ApplyTransform /toolsversion:15.0 /verbosity:minimal C:\Projects\Platform.dev.local\scripts\applytransform.targets
#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 {
@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; }
@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 / 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 / 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