off_telemetry_ps5.ps1 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <#
  2. .SYNOPSIS
  3. Improved comprehensive script to disable telemetry in Microsoft development tools
  4. .DESCRIPTION
  5. This script safely disables telemetry, crash reporting, and data collection for:
  6. - Visual Studio 2015-2022 (only if installed)
  7. - Visual Studio Code (only if installed)
  8. - .NET CLI
  9. - NuGet
  10. - Various Visual Studio services
  11. .NOTES
  12. Must be run as Administrator
  13. Improved safety - only modifies existing registry paths
  14. Compatible with PowerShell 5.x
  15. Includes comprehensive backup and restore functionality
  16. .PARAMETER CreateBackup
  17. Creates registry backup before making changes
  18. .PARAMETER RestoreBackup
  19. Restores registry from backup file
  20. .PARAMETER BackupPath
  21. Path for backup file (default: Desktop)
  22. .EXAMPLE
  23. .\off_telemetry_ps5.ps1 -CreateBackup
  24. .\off_telemetry_ps5.ps1 -RestoreBackup -BackupPath "C:\Backup\registry_backup.reg"
  25. #>
  26. param(
  27. [switch]$CreateBackup,
  28. [switch]$RestoreBackup,
  29. [string]$BackupPath = "$env:USERPROFILE\Desktop\telemetry_backup_$(Get-Date -Format 'yyyyMMdd_HHmmss').reg"
  30. )
  31. $serviceProcessed = $false
  32. # Color scheme for consistent output
  33. $Colors = @{
  34. Title = 'Cyan'
  35. Section = 'Yellow'
  36. Success = 'Green'
  37. Info = 'Blue'
  38. Warning = 'Yellow'
  39. Error = 'Red'
  40. Gray = 'Gray'
  41. }
  42. Write-Host "======================================================" -ForegroundColor $Colors.Title
  43. Write-Host " by EXLOUD" -ForegroundColor $Colors.Title
  44. Write-Host "======================================================" -ForegroundColor $Colors.Title
  45. # =======================================================
  46. # BACKUP AND RESTORE FUNCTIONS
  47. # =======================================================
  48. function New-RegistryBackup {
  49. param([string]$BackupFile)
  50. Write-Host "`n--- Creating Registry Backup ---" -ForegroundColor $Colors.Section
  51. try {
  52. $backupKeys = @(
  53. "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VSCommon",
  54. "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VSCommon",
  55. "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\VisualStudio",
  56. "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio"
  57. )
  58. $backupResult = $true
  59. foreach ($key in $backupKeys) {
  60. $regFile = $BackupFile -replace '\.reg$', "_$($key -replace '[\\:]', '_').reg"
  61. $null = & reg export $key $regFile /y 2>$null
  62. if ($LASTEXITCODE -eq 0) {
  63. Write-Host "✓ Backed up: $key" -ForegroundColor $Colors.Success
  64. } else {
  65. Write-Host "→ Key not found (skipped): $key" -ForegroundColor $Colors.Gray
  66. }
  67. }
  68. Write-Host "✓ Registry backup completed" -ForegroundColor $Colors.Success
  69. return $backupResult
  70. }
  71. catch {
  72. Write-Host "✗ Failed to create backup: $_" -ForegroundColor $Colors.Error
  73. return $false
  74. }
  75. }
  76. function Restore-RegistryBackup {
  77. param([string]$BackupFile)
  78. Write-Host "`n--- Restoring Registry Backup ---" -ForegroundColor $Colors.Section
  79. if (!(Test-Path $BackupFile)) {
  80. Write-Host "✗ Backup file not found: $BackupFile" -ForegroundColor $Colors.Error
  81. return $false
  82. }
  83. try {
  84. $null = & reg import $BackupFile
  85. if ($LASTEXITCODE -eq 0) {
  86. Write-Host "✓ Registry restored from: $BackupFile" -ForegroundColor $Colors.Success
  87. return $true
  88. } else {
  89. Write-Host "✗ Failed to restore registry" -ForegroundColor $Colors.Error
  90. return $false
  91. }
  92. }
  93. catch {
  94. Write-Host "✗ Error restoring backup: $_" -ForegroundColor $Colors.Error
  95. return $false
  96. }
  97. }
  98. # =======================================================
  99. # SAFE REGISTRY FUNCTIONS
  100. # =======================================================
  101. function Set-SafeRegistryValue {
  102. param(
  103. [string]$Path,
  104. [string]$Name,
  105. [object]$Value,
  106. [string]$Type = 'DWORD',
  107. [switch]$CreatePath
  108. )
  109. try {
  110. # Check if path exists
  111. if (!(Test-Path $Path)) {
  112. if ($CreatePath) {
  113. $null = New-Item -Path $Path -Force
  114. Write-Host "→ Created registry path: $Path" -ForegroundColor $Colors.Info
  115. } else {
  116. Write-Host "→ Registry path not found, skipping: $Path" -ForegroundColor $Colors.Gray
  117. return $false
  118. }
  119. } else {
  120. Write-Host "→ Found registry path: $Path" -ForegroundColor $Colors.Info
  121. }
  122. # Check current value
  123. $currentValue = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
  124. if ($currentValue -and $currentValue.$Name -eq $Value) {
  125. Write-Host "✓ $Name already set to $Value" -ForegroundColor $Colors.Success
  126. return $true
  127. }
  128. # Set new value
  129. $null = New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop
  130. Write-Host "✓ Set $Name to $Value in $Path" -ForegroundColor $Colors.Success
  131. return $true
  132. }
  133. catch {
  134. Write-Host "✗ Failed to set $Name in $Path : $_" -ForegroundColor $Colors.Error
  135. return $false
  136. }
  137. }
  138. function Remove-TelemetryDirectory {
  139. param([string]$Path)
  140. if (Test-Path $Path) {
  141. try {
  142. $itemCount = (Get-ChildItem -Path $Path -Recurse -ErrorAction SilentlyContinue | Measure-Object).Count
  143. if ($itemCount -gt 0) {
  144. Remove-Item -Path $Path -Recurse -Force -ErrorAction Stop
  145. Write-Host "✓ Removed telemetry directory: $Path ($itemCount items)" -ForegroundColor $Colors.Success
  146. } else {
  147. Write-Host "→ Telemetry directory already empty: $Path" -ForegroundColor $Colors.Info
  148. }
  149. }
  150. catch {
  151. Write-Host "✗ Failed to remove: $Path - $_" -ForegroundColor $Colors.Error
  152. }
  153. } else {
  154. Write-Host "→ Telemetry directory not found: $Path" -ForegroundColor $Colors.Gray
  155. }
  156. }
  157. function Set-SafeEnvironmentVariable {
  158. param(
  159. [string]$Name,
  160. [string]$Value,
  161. [string]$Target = 'User'
  162. )
  163. try {
  164. $currentValue = [Environment]::GetEnvironmentVariable($Name, $Target)
  165. if ($currentValue -eq $Value) {
  166. Write-Host "✓ $Name already set to $Value" -ForegroundColor $Colors.Success
  167. } else {
  168. [Environment]::SetEnvironmentVariable($Name, $Value, $Target)
  169. Write-Host "✓ Set $Name to $Value" -ForegroundColor $Colors.Success
  170. }
  171. return $true
  172. }
  173. catch {
  174. Write-Host "✗ Failed to set environment variable $Name : $_" -ForegroundColor $Colors.Error
  175. return $false
  176. }
  177. }
  178. # =======================================================
  179. # MAIN SCRIPT LOGIC
  180. # =======================================================
  181. # Handle backup/restore operations
  182. if ($RestoreBackup) {
  183. $null = Restore-RegistryBackup -BackupFile $BackupPath
  184. Write-Host "`nRestore operation completed. Press Enter to exit..." -ForegroundColor $Colors.Info
  185. $null = Read-Host
  186. exit
  187. }
  188. if ($CreateBackup) {
  189. $null = New-RegistryBackup -BackupFile $BackupPath
  190. Write-Host "`nBackup created at: $BackupPath" -ForegroundColor $Colors.Info
  191. Write-Host "You can restore with: .\off_telemetry_ps5.ps1 -RestoreBackup -BackupPath '$BackupPath'" -ForegroundColor $Colors.Info
  192. $continue = Read-Host "`nContinue with telemetry disable? (y/n)"
  193. if ($continue -ne 'y' -and $continue -ne 'Y') {
  194. exit
  195. }
  196. }
  197. # =======================================================
  198. # DETECT INSTALLED VISUAL STUDIO VERSIONS
  199. # =======================================================
  200. Write-Host "`n--- Detecting Installed Visual Studio Versions ---" -ForegroundColor $Colors.Section
  201. $vsVersions = @{
  202. "14.0" = "Visual Studio 2015"
  203. "15.0" = "Visual Studio 2017"
  204. "16.0" = "Visual Studio 2019"
  205. "17.0" = "Visual Studio 2022"
  206. }
  207. $installedVersions = @()
  208. foreach ($version in $vsVersions.Keys) {
  209. $vsName = $vsVersions[$version]
  210. # Check multiple detection methods
  211. $detected = $false
  212. # Method 1: Registry SQM paths
  213. $paths = @(
  214. "HKLM:\SOFTWARE\Microsoft\VSCommon\$version",
  215. "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VSCommon\$version"
  216. )
  217. foreach ($path in $paths) {
  218. if (Test-Path $path) {
  219. $detected = $true
  220. break
  221. }
  222. }
  223. # Method 2: Installation paths
  224. if (!$detected) {
  225. $installPaths = @(
  226. "${env:ProgramFiles}\Microsoft Visual Studio\*\*\Common7\IDE\devenv.exe",
  227. "${env:ProgramFiles(x86)}\Microsoft Visual Studio\*\*\Common7\IDE\devenv.exe",
  228. "${env:ProgramFiles(x86)}\Microsoft Visual Studio $version\*\Common7\IDE\devenv.exe"
  229. )
  230. foreach ($installPath in $installPaths) {
  231. if (Get-ChildItem -Path $installPath -ErrorAction SilentlyContinue) {
  232. $detected = $true
  233. break
  234. }
  235. }
  236. }
  237. if ($detected) {
  238. Write-Host "✓ Detected: $vsName (version $version)" -ForegroundColor $Colors.Success
  239. $installedVersions += $version
  240. } else {
  241. Write-Host "→ Not found: $vsName (version $version)" -ForegroundColor $Colors.Gray
  242. }
  243. }
  244. if ($installedVersions.Count -eq 0) {
  245. Write-Host "→ No Visual Studio installations detected" -ForegroundColor $Colors.Info
  246. }
  247. # =======================================================
  248. # VISUAL STUDIO TELEMETRY DISABLE (EXISTING INSTALLATIONS ONLY)
  249. # =======================================================
  250. Write-Host "`n--- Disabling Visual Studio Telemetry (Detected Installations) ---" -ForegroundColor $Colors.Section
  251. foreach ($version in $installedVersions) {
  252. $vsName = $vsVersions[$version]
  253. Write-Host "`n--- Processing $vsName (version $version) ---" -ForegroundColor $Colors.Info
  254. # Process both architectures
  255. $regPaths = @()
  256. if ([Environment]::Is64BitOperatingSystem) {
  257. $regPaths += "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VSCommon\$version\SQM"
  258. }
  259. $regPaths += "HKLM:\SOFTWARE\Microsoft\VSCommon\$version\SQM"
  260. foreach ($regPath in $regPaths) {
  261. $null = Set-SafeRegistryValue -Path $regPath -Name "OptIn" -Value 0 -Type 'DWORD'
  262. }
  263. # Additional paths for this version
  264. $additionalPaths = @(
  265. "HKCU:\Software\Microsoft\VisualStudio\$version\General"
  266. )
  267. foreach ($path in $additionalPaths) {
  268. $null = Set-SafeRegistryValue -Path $path -Name "EnableSQM" -Value 0 -Type 'DWORD'
  269. }
  270. }
  271. # =======================================================
  272. # VISUAL STUDIO POLICY SETTINGS (CONSERVATIVE APPROACH)
  273. # =======================================================
  274. Write-Host "`n--- Checking Visual Studio Policy Settings ---" -ForegroundColor $Colors.Section
  275. # Only create policy paths if at least one VS version is installed
  276. if ($installedVersions.Count -gt 0) {
  277. Write-Host "→ Visual Studio detected, configuring policies..." -ForegroundColor $Colors.Info
  278. # Policy paths (create only if VS is installed)
  279. $policyPaths = @{
  280. "HKLM:\SOFTWARE\Policies\Microsoft\VisualStudio\Feedback" = @{
  281. "DisableFeedbackDialog" = 1
  282. "DisableEmailInput" = 1
  283. "DisableScreenshotCapture" = 1
  284. }
  285. "HKLM:\SOFTWARE\Policies\Microsoft\VisualStudio\SQM" = @{
  286. "OptIn" = 0
  287. }
  288. "HKCU:\Software\Microsoft\VisualStudio\Telemetry" = @{
  289. "TurnOffSwitch" = 1
  290. }
  291. }
  292. foreach ($path in $policyPaths.Keys) {
  293. $settings = $policyPaths[$path]
  294. foreach ($setting in $settings.GetEnumerator()) {
  295. $null = Set-SafeRegistryValue -Path $path -Name $setting.Key -Value $setting.Value -Type 'DWORD' -CreatePath
  296. }
  297. }
  298. } else {
  299. Write-Host "→ No Visual Studio detected, skipping policy configuration" -ForegroundColor $Colors.Gray
  300. }
  301. # =======================================================
  302. # EXPERIENCE IMPROVEMENT PROGRAM
  303. # =======================================================
  304. Write-Host "`n--- Disabling Customer Experience Improvement Program ---" -ForegroundColor $Colors.Section
  305. $experiencePaths = @(
  306. "HKLM:\SOFTWARE\Microsoft\SQMClient",
  307. "HKLM:\SOFTWARE\Wow6432Node\Microsoft\SQMClient"
  308. )
  309. foreach ($path in $experiencePaths) {
  310. $null = Set-SafeRegistryValue -Path $path -Name "CEIPEnable" -Value 0 -Type 'DWORD'
  311. }
  312. # =======================================================
  313. # TELEMETRY DIRECTORIES CLEANUP
  314. # =======================================================
  315. Write-Host "`n--- Cleaning Telemetry Directories ---" -ForegroundColor $Colors.Section
  316. $telemetryDirs = @(
  317. "$env:APPDATA\vstelemetry",
  318. "$env:LOCALAPPDATA\Microsoft\VSApplicationInsights",
  319. "$env:PROGRAMDATA\Microsoft\VSApplicationInsights",
  320. "$env:TEMP\Microsoft\VSApplicationInsights",
  321. "$env:TEMP\VSFaultInfo",
  322. "$env:TEMP\VSFeedbackIntelliCodeLogs",
  323. "$env:TEMP\VSFeedbackPerfWatsonData",
  324. "$env:TEMP\VSFeedbackVSRTCLogs",
  325. "$env:TEMP\VSRemoteControl",
  326. "$env:TEMP\VSTelem",
  327. "$env:TEMP\VSTelem.Out"
  328. )
  329. foreach ($dir in $telemetryDirs) {
  330. Remove-TelemetryDirectory -Path $dir
  331. }
  332. # =======================================================
  333. # .NET AND NUGET TELEMETRY DISABLE
  334. # =======================================================
  335. Write-Host "`n--- Disabling .NET and NuGet Telemetry ---" -ForegroundColor $Colors.Section
  336. $null = Set-SafeEnvironmentVariable -Name 'DOTNET_CLI_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  337. $null = Set-SafeEnvironmentVariable -Name 'NUGET_TELEMETRY_OPTOUT' -Value 'true' -Target 'User'
  338. # =======================================================
  339. # VISUAL STUDIO STANDARD COLLECTOR SERVICE
  340. # =======================================================
  341. Write-Host "`n--- Managing VS Standard Collector Service ---" -ForegroundColor $Colors.Section
  342. $serviceName = 'VSStandardCollectorService150'
  343. $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
  344. if ($service) {
  345. Write-Host "→ Found service: $serviceName" -ForegroundColor $Colors.Info
  346. # Stop service if running
  347. if ($service.Status -eq 'Running') {
  348. try {
  349. Stop-Service -Name $serviceName -Force -ErrorAction Stop
  350. Write-Host "✓ Stopped $serviceName" -ForegroundColor $Colors.Success
  351. }
  352. catch {
  353. Write-Host "✗ Could not stop $serviceName : $_" -ForegroundColor $Colors.Error
  354. }
  355. } else {
  356. Write-Host "→ Service $serviceName already stopped (Status: $($service.Status))" -ForegroundColor $Colors.Info
  357. }
  358. # Disable service
  359. if ($service.StartType -eq 'Disabled') {
  360. Write-Host "✓ $serviceName already disabled" -ForegroundColor $Colors.Success
  361. } else {
  362. try {
  363. Set-Service -Name $serviceName -StartupType Disabled -Confirm:$false -ErrorAction Stop
  364. Write-Host "✓ Disabled $serviceName" -ForegroundColor $Colors.Success
  365. }
  366. catch {
  367. Write-Host "✗ Could not disable $serviceName : $_" -ForegroundColor $Colors.Error
  368. }
  369. }
  370. } else {
  371. Write-Host "→ $serviceName not found (not installed)" -ForegroundColor $Colors.Gray
  372. }
  373. $serviceProcessed = ($null -ne $service)
  374. # =======================================================
  375. # VISUAL STUDIO CODE SETTINGS
  376. # =======================================================
  377. Write-Host "`n--- Configuring Visual Studio Code Settings ---" -ForegroundColor $Colors.Section
  378. $vscodeSettings = "$env:APPDATA\Code\User\settings.json"
  379. $vscodeUserDir = "$env:APPDATA\Code\User"
  380. $vscodeDetected = $false
  381. if (!(Test-Path "$env:APPDATA\Code")) {
  382. Write-Host "→ Visual Studio Code not detected" -ForegroundColor $Colors.Gray
  383. } else {
  384. Write-Host "→ Visual Studio Code detected" -ForegroundColor $Colors.Info
  385. $vscodeDetected = $true
  386. # Create User directory if needed
  387. if (!(Test-Path $vscodeUserDir)) {
  388. try {
  389. $null = New-Item -Path $vscodeUserDir -ItemType Directory -Force
  390. Write-Host "→ Created VS Code User directory" -ForegroundColor $Colors.Info
  391. } catch {
  392. Write-Host "✗ Failed to create VS Code User directory: $_" -ForegroundColor $Colors.Error
  393. }
  394. }
  395. # Privacy settings
  396. $privacyConfig = @{
  397. "telemetry.enableTelemetry" = $false
  398. "telemetry.enableCrashReporter" = $false
  399. "workbench.enableExperiments" = $false
  400. "update.mode" = "manual"
  401. "update.showReleaseNotes" = $false
  402. "extensions.autoCheckUpdates" = $false
  403. "extensions.showRecommendationsOnlyOnDemand" = $true
  404. "git.autofetch" = $false
  405. "npm.fetchOnlinePackageInfo" = $false
  406. }
  407. try {
  408. # Load existing settings
  409. $settings = @{}
  410. if (Test-Path $vscodeSettings) {
  411. $content = Get-Content $vscodeSettings -Raw -ErrorAction SilentlyContinue
  412. if ($content -and $content.Trim()) {
  413. try {
  414. # Use PowerShell's built-in JSON cmdlets
  415. $settingsObj = $content | ConvertFrom-Json
  416. # Convert PSCustomObject to hashtable for easier manipulation
  417. $settings = @{}
  418. $settingsObj.PSObject.Properties | ForEach-Object {
  419. $settings[$_.Name] = $_.Value
  420. }
  421. Write-Host "→ Found existing VS Code settings file" -ForegroundColor $Colors.Info
  422. }
  423. catch {
  424. Write-Host "→ Could not parse existing settings, creating new ones" -ForegroundColor $Colors.Warning
  425. $settings = @{}
  426. }
  427. }
  428. }
  429. # Update settings
  430. $changesMade = $false
  431. foreach ($key in $privacyConfig.Keys) {
  432. $value = $privacyConfig[$key]
  433. if ($settings.ContainsKey($key) -and $settings[$key] -eq $value) {
  434. Write-Host "✓ $key already set to $value" -ForegroundColor $Colors.Success
  435. } else {
  436. $settings[$key] = $value
  437. Write-Host "✓ Updated $key to $value" -ForegroundColor $Colors.Success
  438. $changesMade = $true
  439. }
  440. }
  441. # Save settings if changes were made
  442. if ($changesMade -or !(Test-Path $vscodeSettings)) {
  443. $json = $settings | ConvertTo-Json -Depth 10
  444. $json | Out-File -FilePath $vscodeSettings -Encoding UTF8
  445. Write-Host "✓ Saved VS Code privacy settings" -ForegroundColor $Colors.Success
  446. } else {
  447. Write-Host "→ No changes needed for VS Code settings" -ForegroundColor $Colors.Info
  448. }
  449. }
  450. catch {
  451. Write-Host "✗ Failed to update VS Code settings: $_" -ForegroundColor $Colors.Error
  452. }
  453. }
  454. # =======================================================
  455. # POWERSHELL TELEMETRY [off] FOR PS 7.x
  456. # =======================================================
  457. # Write-Host "`n--- Disabling PowerShell Telemetry ---" -ForegroundColor $Colors.Section
  458. # $null = Set-SafeEnvironmentVariable -Name 'POWERSHELL_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  459. # =======================================================
  460. # SUMMARY
  461. # =======================================================
  462. Write-Host "`n========================================" -ForegroundColor $Colors.Title
  463. Write-Host "TELEMETRY DISABLE COMPLETE" -ForegroundColor $Colors.Title
  464. Write-Host "========================================" -ForegroundColor $Colors.Title
  465. Write-Host "`nProcessed telemetry settings for:" -ForegroundColor White
  466. # Visual Studio versions with status colors
  467. if ($installedVersions.Count -gt 0) {
  468. foreach ($version in $installedVersions) {
  469. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  470. Write-Host "$($vsVersions[$version]) (detected)" -ForegroundColor $Colors.Success
  471. }
  472. } else {
  473. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  474. Write-Host "No Visual Studio versions detected" -ForegroundColor $Colors.Gray
  475. }
  476. # Visual Studio Code with status colors
  477. if ($vscodeDetected) {
  478. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  479. Write-Host "Visual Studio Code (detected)" -ForegroundColor $Colors.Success
  480. } else {
  481. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  482. Write-Host "Visual Studio Code (not found)" -ForegroundColor $Colors.Gray
  483. }
  484. # Other components with status indicators
  485. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  486. Write-Host ".NET CLI" -ForegroundColor $Colors.Success
  487. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  488. Write-Host "NuGet" -ForegroundColor $Colors.Success
  489. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  490. Write-Host "Settings Synchronization" -ForegroundColor $Colors.Success
  491. # VS Standard Collector Service status
  492. if ($serviceProcessed) {
  493. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  494. Write-Host "VS Standard Collector Service (processed)" -ForegroundColor $Colors.Success
  495. } else {
  496. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray
  497. Write-Host "VS Standard Collector Service (not found)" -ForegroundColor $Colors.Gray
  498. }
  499. # Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  500. # Write-Host "PowerShell" -ForegroundColor $Colors.Success
  501. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  502. Write-Host "Customer Experience Improvement Program" -ForegroundColor $Colors.Success
  503. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success
  504. Write-Host "Telemetry Directories Cleanup" -ForegroundColor $Colors.Success
  505. # =======================================================
  506. # ADDITIONAL FEATURES AND ENVIRONMENT VARIABLES
  507. # =======================================================
  508. Write-Host "`n--- Optional: Additional Features and Environment Variables ---" -ForegroundColor $Colors.Section
  509. Write-Host "This will perform additional configuration:" -ForegroundColor $Colors.Info
  510. Write-Host "• Disable Visual Studio Settings Synchronization" -ForegroundColor $Colors.Info
  511. Write-Host "• Disable Live Share" -ForegroundColor $Colors.Info
  512. Write-Host "• Disable IntelliCode" -ForegroundColor $Colors.Info
  513. Write-Host "• Disable CodeLens" -ForegroundColor $Colors.Info
  514. Write-Host "• Set additional environment variables (INTELLICODE_TELEMETRY_OPTOUT, LIVESHARE_TELEMETRY_OPTOUT, VSSDK_TELEMETRY_OPTOUT)" -ForegroundColor $Colors.Info
  515. $enableAdditional = Read-Host "`nEnable additional configuration? (y/n)"
  516. if ($enableAdditional -eq 'y' -or $enableAdditional -eq 'Y' -or $enableAdditional -eq 'yes' -or $enableAdditional -eq 'Yes' -or $enableAdditional -eq 'YES') {
  517. # =======================================================
  518. # VISUAL STUDIO ADDITIONAL FEATURES DISABLE
  519. # =======================================================
  520. Write-Host "`n--- Disabling Additional Visual Studio Features ---" -ForegroundColor $Colors.Section
  521. if ($installedVersions.Count -gt 0) {
  522. foreach ($version in $installedVersions) {
  523. $vsName = $vsVersions[$version]
  524. Write-Host "`n--- Processing Additional Features for $vsName (version $version) ---" -ForegroundColor $Colors.Info
  525. # =======================================================
  526. # SETTINGS SYNCHRONIZATION
  527. # =======================================================
  528. Write-Host "→ Disabling Settings Synchronization..." -ForegroundColor $Colors.Info
  529. $settingsPaths = @(
  530. "HKCU:\Software\Microsoft\VisualStudio\$version\Settings",
  531. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\Settings"
  532. )
  533. foreach ($path in $settingsPaths) {
  534. $null = Set-SafeRegistryValue -Path $path -Name "SyncSettings" -Value 0 -Type 'DWORD' -CreatePath
  535. $null = Set-SafeRegistryValue -Path $path -Name "EnableRoaming" -Value 0 -Type 'DWORD' -CreatePath
  536. $null = Set-SafeRegistryValue -Path $path -Name "EnableSync" -Value 0 -Type 'DWORD' -CreatePath
  537. $null = Set-SafeRegistryValue -Path $path -Name "DisableSync" -Value 1 -Type 'DWORD' -CreatePath
  538. }
  539. # Additional settings sync paths
  540. $syncPath = "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\ConnectedServices"
  541. $null = Set-SafeRegistryValue -Path $syncPath -Name "Provider.Enabled" -Value 0 -Type 'DWORD' -CreatePath
  542. # =======================================================
  543. # LIVE SHARE
  544. # =======================================================
  545. Write-Host "→ Disabling Live Share..." -ForegroundColor $Colors.Info
  546. $liveSharePaths = @(
  547. "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare",
  548. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\LiveShare"
  549. )
  550. foreach ($path in $liveSharePaths) {
  551. $null = Set-SafeRegistryValue -Path $path -Name "Enabled" -Value 0 -Type 'DWORD' -CreatePath
  552. $null = Set-SafeRegistryValue -Path $path -Name "EnableTelemetry" -Value 0 -Type 'DWORD' -CreatePath
  553. $null = Set-SafeRegistryValue -Path $path -Name "DisableTelemetry" -Value 1 -Type 'DWORD' -CreatePath
  554. $null = Set-SafeRegistryValue -Path $path -Name "OptedIn" -Value 0 -Type 'DWORD' -CreatePath
  555. }
  556. # Live Share telemetry
  557. $liveShareTelemetryPath = "HKCU:\Software\Microsoft\VisualStudio\$version\LiveShare\Telemetry"
  558. $null = Set-SafeRegistryValue -Path $liveShareTelemetryPath -Name "Enabled" -Value 0 -Type 'DWORD' -CreatePath
  559. $null = Set-SafeRegistryValue -Path $liveShareTelemetryPath -Name "OptOut" -Value 1 -Type 'DWORD' -CreatePath
  560. # =======================================================
  561. # INTELLICODE
  562. # =======================================================
  563. Write-Host "→ Disabling IntelliCode..." -ForegroundColor $Colors.Info
  564. $intelliCodePaths = @(
  565. "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode",
  566. "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliSense\IntelliCode",
  567. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\IntelliCode"
  568. )
  569. foreach ($path in $intelliCodePaths) {
  570. $null = Set-SafeRegistryValue -Path $path -Name "DisableTelemetry" -Value 1 -Type 'DWORD' -CreatePath
  571. $null = Set-SafeRegistryValue -Path $path -Name "EnableTelemetry" -Value 0 -Type 'DWORD' -CreatePath
  572. $null = Set-SafeRegistryValue -Path $path -Name "OptedIn" -Value 0 -Type 'DWORD' -CreatePath
  573. $null = Set-SafeRegistryValue -Path $path -Name "Enabled" -Value 0 -Type 'DWORD' -CreatePath
  574. $null = Set-SafeRegistryValue -Path $path -Name "ModelDownloadEnabled" -Value 0 -Type 'DWORD' -CreatePath
  575. }
  576. # IntelliCode privacy settings
  577. $intelliCodePrivacyPath = "HKCU:\Software\Microsoft\VisualStudio\$version\IntelliCode\Privacy"
  578. $null = Set-SafeRegistryValue -Path $intelliCodePrivacyPath -Name "TelemetryOptOut" -Value 1 -Type 'DWORD' -CreatePath
  579. $null = Set-SafeRegistryValue -Path $intelliCodePrivacyPath -Name "DataCollection" -Value 0 -Type 'DWORD' -CreatePath
  580. $null = Set-SafeRegistryValue -Path $intelliCodePrivacyPath -Name "UsageDataOptOut" -Value 1 -Type 'DWORD' -CreatePath
  581. # =======================================================
  582. # CODELENS
  583. # =======================================================
  584. Write-Host "→ Disabling CodeLens..." -ForegroundColor $Colors.Info
  585. $codeLensPaths = @(
  586. "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens",
  587. "HKCU:\Software\Microsoft\VisualStudio\$version\TextEditor\CodeLens",
  588. "HKCU:\Software\Microsoft\VisualStudio\$version\ApplicationPrivateSettings\Microsoft\VisualStudio\CodeLens"
  589. )
  590. foreach ($path in $codeLensPaths) {
  591. $null = Set-SafeRegistryValue -Path $path -Name "Disabled" -Value 1 -Type 'DWORD' -CreatePath
  592. $null = Set-SafeRegistryValue -Path $path -Name "ShowAuthorCodeLens" -Value 0 -Type 'DWORD' -CreatePath
  593. $null = Set-SafeRegistryValue -Path $path -Name "ShowReferencesCodeLens" -Value 0 -Type 'DWORD' -CreatePath
  594. $null = Set-SafeRegistryValue -Path $path -Name "ShowTestCodeLens" -Value 0 -Type 'DWORD' -CreatePath
  595. $null = Set-SafeRegistryValue -Path $path -Name "Enabled" -Value 0 -Type 'DWORD' -CreatePath
  596. }
  597. # CodeLens telemetry
  598. $codeLensTelemetryPath = "HKCU:\Software\Microsoft\VisualStudio\$version\CodeLens\Telemetry"
  599. $null = Set-SafeRegistryValue -Path $codeLensTelemetryPath -Name "Enabled" -Value 0 -Type 'DWORD' -CreatePath
  600. $null = Set-SafeRegistryValue -Path $codeLensTelemetryPath -Name "OptOut" -Value 1 -Type 'DWORD' -CreatePath
  601. }
  602. } else {
  603. Write-Host "→ No Visual Studio installations detected, skipping additional features" -ForegroundColor $Colors.Gray
  604. }
  605. # =======================================================
  606. # ADDITIONAL ENVIRONMENT VARIABLES
  607. # =======================================================
  608. Write-Host "`n--- Setting Additional Environment Variables ---" -ForegroundColor $Colors.Section
  609. $null = Set-SafeEnvironmentVariable -Name 'INTELLICODE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  610. $null = Set-SafeEnvironmentVariable -Name 'LIVESHARE_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  611. $null = Set-SafeEnvironmentVariable -Name 'VSSDK_TELEMETRY_OPTOUT' -Value '1' -Target 'User'
  612. Write-Host "`n✓ Additional configuration completed" -ForegroundColor $Colors.Success
  613. } else {
  614. Write-Host "→ Skipping additional configuration" -ForegroundColor $Colors.Info
  615. }
  616. Write-Host "`nLegend:" -ForegroundColor White
  617. Write-Host "✓ " -NoNewline -ForegroundColor $Colors.Success; Write-Host "Action completed successfully"
  618. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Info; Write-Host "Information or preparatory action"
  619. Write-Host "→ " -NoNewline -ForegroundColor $Colors.Gray; Write-Host "Component not found, skipped"
  620. Write-Host "✗ " -NoNewline -ForegroundColor $Colors.Error; Write-Host "Error occurred"
  621. if (!$CreateBackup) {
  622. Write-Host "`nTip: Run with -CreateBackup parameter to create registry backup first" -ForegroundColor $Colors.Warning
  623. }
  624. Write-Host "`nRestart may be required for all changes to take effect." -ForegroundColor $Colors.Warning
  625. Write-Host "Press Enter to exit..." -ForegroundColor White
  626. $null = Read-Host