-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tfs2017ThemeColorRestore.ps1
137 lines (104 loc) · 3.85 KB
/
Tfs2017ThemeColorRestore.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
param
(
$TfsPath="C:\Program Files\Microsoft Team Foundation Server 15.0",
$AppThemesPath="auto"
)
#=================================================== FUNCTIONS ===================================================
function Set-AppThemesPathParameter
{
$MatchFolders = Get-ChildItem "$TfsPath\Application Tier\Web Services\_static\tfs" -Filter Dev15.*
if($MatchFolders -eq $null)
{
Write-Host "Error, Any file with the pattern 'Dev15*' was found under $TfsPath\Application Tier\Web Services\_static\tfs}"
Write-Host "AppThemesPath parameter can be automatically set" -ForegroundColor Red
Exit
}
elseif($MatchFolders.GetType().Name -eq "Object[]")
{
Write-Host "Error, Several files with the pattern 'Dev15*' were found under {$TfsPath\Application Tier\Web Services\_static\tfs}" -ForegroundColor Red
Write-Host "AppThemesPath parameter can be automatically set" -ForegroundColor Red
Exit
}
else
{
$DevFolder=$MatchFolders.Name
$AppThemesPath="$TfsPath\Application Tier\Web Services\_static\tfs\$DevFolder\App_Themes"
Write-Host "AppThemesPath [$AppThemesPath]"
return $AppThemesPath
}
}
function Restore-AppThemesFolder
{
Write-Host "Restoring default theme colors..."
if(Test-Path $AppThemesPath){ Remove-Item -Path $AppThemesPath -Recurse -Force}
Move-Item -Path "$AppThemesPath-Backup" -Destination $AppThemesPath -Force
Write-Host ""
Write-Host "Theme colors successfully restored!" -ForegroundColor Yellow
}
function Stop-TFS
{
Write-Host ""
Write-Host ""
Write-Host "Restarting TFS, Shuting Down..."
# Setup the Process startup info
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$TfsPath\Tools\TfsServiceControl.exe"
$pinfo.Arguments = "quiesce"
$pinfo.UseShellExecute = $false
$pinfo.CreateNoWindow = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardError = $true
$pinfo.WorkingDirectory = Get-Location
# Create a process object using the startup info
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $pinfo
# Start the process
$process.Start() | Out-Null
$process.WaitForExit()
Write-Host $process.StandardOutput.ReadToEnd() -ForegroundColor Gray
Write-Host "TFS Stopped!" -ForegroundColor Yellow
}
function Start-TFS
{
Write-Host ""
Write-Host ""
Write-Host "Restarting TFS, Starting TFS..."
# Setup the Process startup info
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$TfsPath\Tools\TfsServiceControl.exe"
$pinfo.Arguments = "unquiesce"
$pinfo.UseShellExecute = $false
$pinfo.CreateNoWindow = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardError = $true
$pinfo.WorkingDirectory = Get-Location
# Create a process object using the startup info
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $pinfo
# Start the process
$process.Start() | Out-Null
$process.WaitForExit()
Write-Host $process.StandardOutput.ReadToEnd() -ForegroundColor Gray
Write-Host "TFS Started!" -ForegroundColor Yellow
}
#====================================================== INIT =====================================================
if($AppThemesPath -eq "auto")
{
$AppThemesPath = Set-AppThemesPathParameter
}
if(-not (Test-Path "$AppThemesPath-Backup"))
{
Write-Host "Error, Backup not found {$AppThemesPath-Backup}" -ForegroundColor Red
}
else
{
Restore-AppThemesFolder
Stop-TFS
Start-TFS
Write-Host ""
Write-Host ""
Write-Host "Process successfully finished!" -ForegroundColor Green
Write-Host ""
Write-Host ""
}
#=================================================================================================================