-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathUpdateInstallationKey.v02.ps1
110 lines (92 loc) · 3.87 KB
/
UpdateInstallationKey.v02.ps1
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)][ValidateLength (12,12)] [string]$installationkey ## Replacement Installation Key
)
clear-host
#$scriptpath = $MyInvocation.MyCommand.Path
#$dir = Split-Path $scriptpath
#Push-Location $dir
Function Update-Config {
try {
Install-Package -Name nuget -Confirm:$False -Force ## https://docs.microsoft.com/en-us/nuget/reference/powershell-reference
}
catch [Exception] {
$_.message
break
}
if (Get-Module -ListAvailable -Name PsIni) {
Write-Host " Module PsIni Already Installed"
}
else {
try {
Install-Module -Name PsIni -Confirm:$False -Force ## https://www.powershellgallery.com/packages/PsIni
}
catch [Exception] {
$_.message
break
}
}
$config = "C:\Program Files\Backup Manager\config.ini"
$General = @{}
$General.Add("Password","$installationkey")
Get-IniContent $config | Set-IniContent -Sections 'General' -NameValuePairs $General | Out-IniFile $config -Pretty -Force -Encoding ASCII
}
Function Stop-BackupProcess {
stop-process -name "BackupFP" -Force -ErrorAction SilentlyContinue
}
Function Stop-BackupService {
$BackupService = get-service -name "Backup Service Controller" -ErrorAction SilentlyContinue
if ($BackupService.Status -eq "Stopped") {
Write-Output " Backup Service : $($BackupService.status)"
}else{
Write-Output " Backup Service : $($BackupService.status)"
stop-service -name "Backup Service Controller" -force -ErrorAction SilentlyContinue
Get-BackupService
}
}
Function Start-BackupService {
$BackupService = get-service -name "Backup Service Controller" -ErrorAction SilentlyContinue
if ($BackupService.Status -eq "Running") {
Write-Output " Backup Service : $($BackupService.status)"
Get-InitError
}else{
Write-Output " Backup Service : $($BackupService.status)"
start-service -name "Backup Service Controller" -ErrorAction SilentlyContinue
Get-BackupService
Get-InitError
}
}
Function Get-BackupService {
$BackupService = get-service -name "Backup Service Controller" -ErrorAction SilentlyContinue
if ($backupservice.status -eq "Stopped") {
Write-Output " Backup Service : $($BackupService.status)"
}
elseif ($backupservice.status -eq "Running") {
Write-Output " Backup Service : $($BackupService.status)"
#start-sleep -seconds 10
#$initmsg = & $clienttool control.initialization-error.get | ConvertFrom-Json -ErrorAction SilentlyContinue
#if ($($initmsg.message)) { Write-Output " InitMsg Error : $($initmsg.message)" }
}
else{
Write-Output " Backup Service : Not Present"
}
}
Function Get-InitError {
$clienttool = "c:\program files\backup manager\clienttool.exe"
start-sleep -seconds 10
$initmsg = & $clienttool control.initialization-error.get | ConvertFrom-Json -ErrorAction SilentlyContinue
if ($($initmsg.message)) { Write-Output " InitMsg Error : $($initmsg.message)" }
}
Function Get-AppStatus {
$clienttool = "c:\program files\backup manager\clienttool.exe"
start-sleep -seconds 30
& "$clienttool" control.application-status.get
& "$clienttool" control.status.get
}
Update-Config
Stop-BackupProcess
Stop-BackupService
Start-BackupService
Get-BackupService
Get-InitError
Get-AppStatus