Created
July 24, 2019 07:29
-
-
Save tackme31/0f8e2d7bbf27a929846e4323defa3f14 to your computer and use it in GitHub Desktop.
A PowerShell script for updating the thumbprint of the xConnect certification in Sitecore 9.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
param ( | |
[Parameter(Mandatory=$true)] | |
[string] | |
$SitePrefix, | |
[Parameter(Mandatory=$true)] | |
[string] | |
$PfxFileOrThumbprint | |
) | |
Import-Module WebAdministration | |
$OutputEncoding='utf-8' | |
if (Test-Path $PfxFileOrThumbprint) { | |
$Thumbprint = Get-PfxCertificate $PfxFileOrThumbprint | Select-Object -ExpandProperty Thumbprint | |
} | |
elseif ($PfxFileOrThumbprint -match "[0-9A-F]{40}") { | |
$Thumbprint = $PfxFileOrThumbprint | |
} | |
else { | |
Write-Error "Invalid parameter [PfxFileOrThumbprint]: $($PfxFileOrThumbprint)" | |
Exit | |
} | |
$sitePaths = Get-ChildItem IIS:\Sites | ? Name -like "$($SitePrefix)*" | % { $_.PhysicalPath -replace "physicalPath=" } | |
## Update ConnectionStrings.config | |
$sitePaths | Get-ChildItem -Filter "ConnectionStrings.config" -Recurse | % { | |
$xmlDoc = [xml](Get-Content $_.FullName) | |
if (-not $xmlDoc.connectionStrings) { | |
return | |
} | |
Write-Output "Update: $($_.FullName)" | |
$xmlDoc.connectionStrings.add | Where-Object { $_.connectionString.Contains("FindByThumbprint") } | % { | |
$_.connectionString = $_.connectionString -replace "[0-9A-F]{40}",$Thumbprint | |
} | |
$xmlDoc.Save($_.FullName) | |
} | |
## Update AppStrings.config | |
$sitePaths | Get-ChildItem -Filter "AppSettings.config" -Recurse | % { | |
$xmlDoc = [xml](Get-Content $_.FullName) | |
if (-not $xmlDoc.connectionStrings) { | |
return | |
} | |
$xmlDoc.appSettings.add | Where-Object { $_.key -eq "validateCertificateThumbprint" } | % { | |
$_.value = $Thumbprint | |
} | |
$xmlDoc.Save($_.FullName) | |
} | |
## Restart xConnect services | |
Get-Service -Name "*$($SitePrefix)*" | Restart-Service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment