Skip to content

Instantly share code, notes, and snippets.

@tackme31
Created July 9, 2019 04:42
Show Gist options
  • Save tackme31/a6efeb916227d39e0cea84285fdb4e34 to your computer and use it in GitHub Desktop.
Save tackme31/a6efeb916227d39e0cea84285fdb4e34 to your computer and use it in GitHub Desktop.
A PowerShell script for updating the licenses of Sitecore 9.x
#Requires -RunAsAdministrator
param (
[Parameter(Mandatory=$true)]
[string]
$SitePrefix,
[Parameter(Mandatory=$false)]
[string]
$LicensePath = "$PSScriptRoot/license.xml",
[switch]
$WhatIf
)
Import-Module WebAdministration
if (-not $(Test-Path $LicensePath)) {
Write-Error "The license file does not exist: $LicensePath"
Exit
}
$sites = Get-ChildItem IIS:\Sites | ? Name -like "*$($SitePrefix)*"
if (-not $sites) {
Write-Error "No websites found."
Exit
}
$licenses = $sites | % { $_.PhysicalPath -replace "physicalPath=" } | Get-ChildItem -Filter "license.xml" -Recurse
$licenses | % {
Copy-Item -Path $_.FullName -Destination "$($_.FullName).old" -Force -WhatIf:$WhatIf
Copy-Item -Path $LicensePath -Destination $_.FullName -Force -WhatIf:$WhatIf
}
Get-Service -Name "*$($SitePrefix)*" | Restart-Service -WhatIf:$WhatIf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment