-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
set-telemetry.ps1
37 lines (30 loc) · 1.16 KB
/
set-telemetry.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
[CmdletBinding()]
Param(
[string] $Enabled = ''
)
[bool]$telemetryEnabled = -not [string]::IsNullOrWhiteSpace($Enabled);
[string]$userAppDataPath = Join-Path -Path $env:APPDATA -ChildPath 'GitExtensions\GitExtensions\GitExtensions.settings'
if (-not (Test-Path -Path $userAppDataPath)) {
'<?xml version="1.0" encoding="utf-8"?><dictionary />' | Out-File $userAppDataPath -Encoding utf8
}
[xml]$doc = Get-Content $userAppDataPath
if (!$doc) {
$doc = '<?xml version="1.0" encoding="utf-8"?>';
}
$node = $doc.SelectSingleNode("/dictionary/item/key/string[text()='TelemetryEnabled']")
if ($node -ne $null) {
$node.ParentNode.ParentNode.value.string = "$telemetryEnabled";
$doc.Save($userAppDataPath)
exit 0
}
$topNode = $doc.SelectSingleNode("/dictionary");
if ($topNode -eq $null) {
$topNode = $doc.CreateElement('dictionary');
$_ = $doc.AppendChild($topNode);
}
$node = $doc.CreateElement('item');
$node.InnerXml = "<key><string>TelemetryEnabled</string></key><value><string>$telemetryEnabled</string></value>";
$_ = $topNode.AppendChild($node);
$doc.Save($userAppDataPath)
# this script now deletes itself
Remove-Item $MyINvocation.InvocationName