Skip to content

Instantly share code, notes, and snippets.

@jhorsman
jhorsman / encrypt.ps1
Created October 3, 2018 19:46
Encrypt web.cofig sections with PowerShell
# from https://joshjoubert.wordpress.com/2013/03/28/encrypting-and-decrypting-sections-of-a-web-config-with-powershell/
# example: Encrypt-ConfigurationSection 1 ‘/WebApplication1’ ‘connectionStrings’ ‘v4.0.30319’
function Encrypt-ConfigurationSection([int] $id, [string] $app, [string] $section, [string] $version){
$currentDirectory = (Get-Location)
Set-Location "C:\windows\Microsoft.Net\Framework\$version\"
.\aspnet_regiis.exe -pe $section -app $app -site $id -prov "RsaProtectedConfigurationProvider"
Set-Location $currentDirectory
}
@jhorsman
jhorsman / TcmUri.cs
Last active January 6, 2022 22:40
TcmUri object for .NET
using System;
using System.Text.RegularExpressions;
using Tridion.ContentManager.CoreService.Client;
namespace TridionUtils
{
/// <summary>
/// Creates TcmUri class from a string. Makes it easy to retrieve TcmUri properties like PublicationId, ItemId, ItemTypeId and Version.
/// Usage: var PubliationId = new TcmUri("tcm:45-3456-64").PublicationId;
/// </summary>

Commands for the XO Bootcamp.

Handy for copy / pasting

File locations:

  • Elasticsearch: C:\Elasticsearch
  • Installation files: C:\Users\Administrator\Downloads\Tridion Sites 9\Content Delivery\roles\xo\resources\elasticsearch
  • Website root and Query example: C:\Inetpub\wwwroot\QueryBuilder.aspx
@jhorsman
jhorsman / get-publications.ps1
Created July 5, 2018 11:25
get-publications.ps1
#Requires -Version 5.0
[CmdletBinding()]
Param(
[parameter(Mandatory=$false, HelpMessage="Endpoint to the discovery service. By default it is on port 8082 and it always ends with /discovery.svc")]
[string]$DiscoveryEndpointUrl = 'http://localhost:8082/discovery.svc',
[parameter(Mandatory=$false, HelpMessage="Use micro service URLs relative to the DiscoveryEndpointUrl URL.")]
[switch]$Local,
@jhorsman
jhorsman / sqlite.ps1
Created May 14, 2018 10:20
Use SQLite with PowerShell
if (-not (Get-Module PSSQLite -ListAvailable)) {
Install-Module PSSQLite
}
Import-Module PSSQLite
$Database = Join-Path $PSScriptRoot "example.sqlite"
#Invoke-SqliteQuery -DataSource $Database -Query "SELECT name FROM sqlite_master WHERE type='table';"
#Invoke-SqliteQuery -DataSource $Database -Query "PRAGMA table_info('MY_TABLE')"
@jhorsman
jhorsman / start-CD-microservices.ps1
Last active January 6, 2022 22:41
Scripted start SDL Web 8.5 microservices
# This script can be used to manually start Tridion Sites micro-services
#
# On some all-in-one Tridion machines I use this script as a scheduled task to have a
# delayed start of the CD micro-services. The transcript creates a log file.
Start-Transcript -Path (Join-Path $PSScriptRoot "start-CD-services.log") -Append
Start-Service SDLWeb*DiscoveryService -Verbose
Start-Service SDLWeb*DeployerService -Verbose
Start-Service SDLWeb*ContentService -Verbose
void Main()
{
var client =
getClient("SERVER", "USER", "PASSWORD", "DOMAIN");
Console.WriteLine("Starting V" + client.GetApiVersion());
}
SessionAwareCoreServiceClient getClient(string hostName, string username,string password, string domain = null)
{
@jhorsman
jhorsman / installService.ps1
Created March 1, 2018 14:13
Install SDL Web Content Delivery mico service with Windows service dependency
....
# $dependsOn should not just contain the name of the service, but the full command line parameter like so:
$dependsOn='--DependsOn="SDLWebDiscoveryService"'
...
@jhorsman
jhorsman / echo.bat
Last active February 27, 2018 08:14
The wrong way to call a dodgy PowerShell script with an array of arguments
# this is a somewhat dodgy way of using arguments in PowerShell
# it would be much nicer to use proper Powershell parameters
Write-Host "The script args are..."
foreach($arg in $args) {
Write-Host $arg
}
@jhorsman
jhorsman / echo.bat
Last active February 27, 2018 08:08
Call a script with an array of arguments in PowerShell
@ECHO off
ECHO The %~nx0 script args are...
for %%I IN (%*) DO ECHO %%I