Created
July 9, 2019 04:42
-
-
Save tackme31/a6efeb916227d39e0cea84285fdb4e34 to your computer and use it in GitHub Desktop.
A PowerShell script for updating the licenses of 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=$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