-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-KenticoLicenseKeys.ps1
More file actions
52 lines (42 loc) · 2.87 KB
/
Update-KenticoLicenseKeys.ps1
File metadata and controls
52 lines (42 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Install-Module -Name SqlServer -AllowClobber
$KenticoDirectory = Get-Item (Read-Host "Please provide the local path to the Kentico solution directory, (e.g., D:\tfs\ATNWorkingProject\Kentico11\ATNKv*_Production)") -Verbose -ErrorAction Stop
if(!$KenticoDirectory.PSIsContainer) {
Write-Error "'$($KenticoDirectory.FullName)' IS NOT A DIRECTORY!"
}
$WebConfigFile = Get-Item "$($KenticoDirectory)\CMS\web.config" -Verbose -ErrorAction Stop
[xml]$WebConfigXml = Get-Content $WebConfigFile.FullName
$CmsConnectionStringNode = $WebConfigXml.SelectSingleNode('/configuration/connectionStrings/add[@name="CMSConnectionString"]')
$CmsConnectionStringValue = $CmsConnectionStringNode.connectionString
$LicenseKeyValues = Invoke-Sqlcmd -ConnectionString $CmsConnectionStringValue -Query "SELECT * FROM CMS_LicenseKey"
$KenticoVersion = (Invoke-Sqlcmd -ConnectionString $CmsConnectionStringValue -Query "SELECT KeyValue FROM CMS_SettingsKey WHERE KeyName = 'CMSDBVersion'").KeyValue
$ResultsCount = 1
$SingletonExists = $true
if($LicenseKeyValues.length -gt 0) {
$SingletonExists = $false
$ResultsCount = $LicenseKeyValues.length
}
for($i = 0; $i -lt $ResultsCount; $i++) {
$LicenseKeyDataRow = $LicenseKeyValues[$i]
if($SingletonExists) {
$LicenseKeyDataRow = $LicenseKeyValues
}
$LicenseKeyID = $LicenseKeyDataRow.LicenseKeyID
$LicenseDomain = $LicenseKeyDataRow.LicenseDomain
$LicenseKey = $LicenseKeyDataRow.LicenseKey
$LicenseEdition = $LicenseKeyDataRow.LicenseEdition
$LicenseExpiration = $LicenseKeyDataRow.LicenseExpiration
$LicenseServers = $LicenseKeyDataRow.LicenseServers
if($LicenseEdition -eq 'U') {
$LicenseEdition = 'V'
}
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to update the Kentico v$($KenticoVersion) license key for the domain '$($LicenseDomain)'?", `
0,"Update License",4)
If ($intAnswer -ne 6) {
continue
}
$NewLicenseKeyFile = Get-Item (Read-Host "Please provide the local path to the Kentico v$($KenticoVersion) license for the domain '$($LicenseDomain)', (e.g., C:\license_[domain]_v11.txt") -Verbose -ErrorAction Stop
Invoke-Sqlcmd -ConnectionString $CmsConnectionStringValue -Query "UPDATE CMS_LicenseKey SET LicenseKey = '$(Get-Content $NewLicenseKeyFile.FullName -Raw -Verbose -ErrorAction Stop)', LicenseEdition = 'V' WHERE LicenseDomain = '$($LicenseDomain)'"
# Invoke-Sqlcmd -ConnectionString $CmsConnectionStringValue -Query "DELETE FROM CMS_LicenseKey WHERE LicenseDomain = '$($LicenseDomain)'"
# Invoke-Sqlcmd -ConnectionString $CmsConnectionStringValue -Query "INSERT INTO CMS_LicenseKey (LicenseDomain, LicenseKey, LicenseEdition, LicenseExpiration, LicenseServers) VALUES ('$($LicenseDomain)', '$(Get-Content $NewLicenseKeyFile.FullName -Raw -Verbose -ErrorAction Stop)', '$($LicenseEdition)', '$($LicenseExpiration)', '$($LicenseServers)')"
}