Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@MartinMiles
MartinMiles / Watch-CreatedFolder.ps1
Created December 5, 2021 23:46
Watches at some folder for a child folder being created, then triggers some action
$global:MonitoredPath = 'c:\inetpub\wwwroot'
$global:ExpectedDirectory = 'xp.xconnect'
$global:KeepGoing = $true
$IncludeSubfolders = $true
$AttributeFilter = [IO.NotifyFilters]::DirectoryName
try
{
$watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{
@MartinMiles
MartinMiles / Disable-TLS_1.3.ps1
Last active January 9, 2024 04:57
Disables TLS 1.3 over TCP for the local IIS
New-Item `
'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' `
-Force | Out-Null
New-ItemProperty `
-path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' `
-name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null
New-ItemProperty `
-path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' `
@MartinMiles
MartinMiles / ThreadPing.ps1
Created November 7, 2021 01:14
A multithreaded network ping written on PwerShell
Param (
[string[]]$Address = $(1..20 | %{"192.168.1.$_"}),
[int]$Threads = 5
)
write-host "Distributing addresses around jobs"
$JobAddresses = @{}
$CurJob = 0
$CurAddress = 0
while ($CurAddress -lt $Address.count)
@MartinMiles
MartinMiles / Update-Compilers.ps1
Created April 20, 2021 22:45
Updates Microsoft.Net.Compilers and Microsoft.CodeDom.Providers.DotNetCompilerPlatform for th latest version across the whole solution within *.csproj and packages.config files
gci -r -include "*.csproj" | foreach-object { $a = $_.fullname; ( Get-Content -Raw $a -Encoding UTF8) | foreach-object { $_ -replace 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform.\d+.\d+.\d+\\build\\net\d{1,3}\\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props','Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets' } | set-content -NoNewLine $a -Encoding UTF8}
gci -r -include "*.csproj" | foreach-object { $a = $_.fullname; ( Get-Content -Raw $a -Encoding UTF8) | foreach-object { $_ -replace 'Microsoft.Net.Compilers.\d+.\d+.\d+','Microsoft.Net.Compilers.3.9.0' } | set-content -NoNewLine $a -Encoding UTF8}
gci -r -include "packages.config" | foreach-object { $a = $_.fullname; ( Get-Content -Raw $a -Encoding UTF8) | foreach-object { $_ -replace '<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="\d+.\d+.\d+" targetFramework="net\d{1,3}" ','<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatfo
@MartinMiles
MartinMiles / Update-ReferencesAndRuntime.ps1
Last active February 15, 2021 09:57
Mass reference and dependency updater for Sitecore upgrades. This one updates Sitecore references for the existing solution and runtime from 8.2.3 to 10.0.1
# You may want to clean up \bin and \obj folders
#Get-ChildItem .\ -include bin,obj -Recurse | ForEach-Object ($_) { Remove-Item $_.FullName -Force -Recurse }
gci -r -include "*.csproj" | foreach-object { $a = $_.fullname; ( Get-Content -Raw $a -Encoding UTF8) | foreach-object { $_ -replace '<Project ToolsVersion="12.0"','<Project ToolsVersion="15.0"' } | set-content -NoNewLine $a -Encoding UTF8}
gci -r -include "*.csproj" | foreach-object { $a = $_.fullname; ( Get-Content -Raw $a -Encoding UTF8) | foreach-object { $_ -replace '<TargetFrameworkVersion>v4\.\d\.\d</TargetFrameworkVersion>','<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>' } | set-content -NoNewLine $a -Encoding UTF8}
gci -r -include "web.config" | foreach-object { $a = $_.fullname; ( Get-Content -Raw $a -Encoding UTF8) | foreach-object { $_ -replace '<compilation debug="true" targetFramework="4.6.1"','<compilation debug="true" targetFramework="4.8"' } | set-content -NoNewLine $a -Encoding UTF8}
@MartinMiles
MartinMiles / Publishing.Service-azure.parameters.json
Created January 24, 2021 02:32
This is the required delta to be added to your azure.parameters.json in order to install Publishing Service into PaaS (modify script values!)
"modules": {
"value": {
"items": [
{
"name": "ps",
"templateLink": "https://yourdomain.com/ps-arm/<version>/azuredeploy.json",
"parameters": {
"templateLinkAccessToken": "Optional access token for the template if stored in Azure storage. Otherwise should be empty string.",
"psMsDeployPackageUrl": "<URL of the WDP file Sitecore Publishing Service *-x64.wdp.zip>",
"psModuleMsDeployPackageUrl": "<URL of the WDP file Sitecore Publishing Module *.scwdp.zip>"
@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