-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tfs2017ThemeColorUpdater.ps1
172 lines (131 loc) · 4.96 KB
/
Tfs2017ThemeColorUpdater.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
param
(
$CurrentPrimaryColor="#0078d7",
$CurrentSecondaryColor="#106ebe",
$CurrentThirdColor="#005a9e",
$CurrentFourthColor="#015a9e",
$NewPrimaryColor="#e60000",
$NewSecondaryColor="#cc0000",
$NewThirdColor="#b30000",
$NewFourthColor="#b30000",
$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 Create-AppThemesBackup
{
Write-Host "Creating a Backup..."
if(-not(Test-Path "$AppThemesPath-Backup")){ Copy-Item -Path $AppThemesPath -Recurse -Destination "$AppThemesPath-Backup" }
else { Write-Host "Backup already exist" -ForegroundColor Gray}
Write-Host ""
Write-Host "Backup successfully created!" -ForegroundColor Yellow
}
function Update-CssFiles
{
Write-Host ""
Write-Host ""
Write-Host "Updating css files..."
$CssFiles = Get-ChildItem -Recurse -Path $AppThemesPath | Where-Object { $_.Extension -eq ".css"}
foreach($file in $CssFiles)
{
$FilePath = $file.FullName
Write-Host "Updating File {$FilePath}..." -ForegroundColor Gray
(Get-Content $FilePath) -replace $CurrentPrimaryColor,$NewPrimaryColor | out-file $FilePath
(Get-Content $FilePath) -replace $CurrentSecondaryColor,$NewSecondaryColor | out-file $FilePath
(Get-Content $FilePath) -replace $CurrentThirdColor,$NewThirdColor | out-file $FilePath
(Get-Content $FilePath) -replace $CurrentFourthColor,$NewFourthColor | out-file $FilePath
}
Write-Host ""
Write-Host "Files successfully updated!" -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))
{
Write-Host "Error, Folder {$AppThemesPath} not found" -ForegroundColor Red
}
else
{
Create-AppThemesBackup
Update-CssFiles
Stop-TFS
Start-TFS
Write-Host ""
Write-Host ""
Write-Host "Process successfully finished!" -ForegroundColor Green
Write-Host ""
Write-Host ""
}
#=================================================================================================================