-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFix-RDCProfileBloat.ps1
More file actions
56 lines (39 loc) · 1.77 KB
/
Copy pathFix-RDCProfileBloat.ps1
File metadata and controls
56 lines (39 loc) · 1.77 KB
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
<#
.SYNOPSIS
Remediates bloated user profiles caused by MSI Remote Desktop Client telemetry.
.DESCRIPTION
This script iterates through all local user profiles, removes the DiagConnectionCache registry key,
and disables EnableMSRDCTelemetry to prevent future bloating of ntuser.dat.
.NOTES
Test before running in production. Run as Administrator.
#>
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
$sids = Get-ChildItem -Path $regPath
$excludedUsers = @('DefaultAccount','WDAGUtilityAccount','Werther','administrator')
foreach ($sid in $sids) {
$profilePath = (Get-ItemProperty -Path $sid.PSPath).ProfileImagePath
if ($profilePath) {
$userName = Split-Path -Leaf $profilePath
if ($excludedUsers -notcontains $userName) {
$userSid = $sid.PSChildName
Write-Output "Processing user: $userName (SID: $userSid)"
# Remove DiagConnectionCache
$rdcRegCache = "Registry::HKEY_USERS\$userSid\Software\Microsoft\RdClientRadc\DiagConnectionCache"
if (Test-Path $rdcRegCache) {
Remove-Item -Path $rdcRegCache -Recurse -Force
Write-Output "Removed: $rdcRegCache"
} else {
Write-Output "Not found: $rdcRegCache"
}
# Disable telemetry
$rdcRegRoot = "Registry::HKEY_USERS\$userSid\Software\Microsoft\RdClientRadc"
if (Test-Path $rdcRegRoot) {
Set-ItemProperty -Path $rdcRegRoot -Name "EnableMSRDCTelemetry" -Value 0
Write-Output "Telemetry disabled: $rdcRegRoot"
} else {
Write-Output "Not found: $rdcRegRoot"
}
}
}
}
Write-Output "Script completed."