Files
winapps/oem/NetProfileCleanup.ps1
T

31 lines
1.1 KiB
PowerShell
Raw Normal View History

2024-12-13 20:06:30 +01:00
# Get the current network profile name
2024-12-18 10:58:39 +01:00
$currentProfile = (Get-NetConnectionProfile).Name
2024-12-13 20:06:30 +01:00
# Get all profiles from the registry
$profilesKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles"
$profiles = Get-ChildItem -Path $profilesKey
2024-12-18 10:58:39 +01:00
foreach ($profile in $profiles) {
2024-12-13 20:06:30 +01:00
$profilePath = "$profilesKey\$($profile.PSChildName)"
2024-12-18 10:58:39 +01:00
$profileName = (Get-ItemProperty -Path $profilePath).ProfileName
2024-12-13 20:06:30 +01:00
# Remove profiles that don't match the current one
2024-12-18 10:58:39 +01:00
if ($profileName -ne $currentProfile) {
2024-12-13 20:06:30 +01:00
Remove-Item -Path $profilePath -Recurse
Write-Host "Deleted profile: $profileName"
}
}
# Change the current profile name to "WinApps"
$profiles = Get-ChildItem -Path $profilesKey
2024-12-18 10:58:39 +01:00
foreach ($profile in $profiles) {
2024-12-13 20:06:30 +01:00
$profilePath = "$profilesKey\$($profile.PSChildName)"
2024-12-18 10:58:39 +01:00
$profileName = (Get-ItemProperty -Path $profilePath).ProfileName
2024-12-13 20:06:30 +01:00
2024-12-18 10:58:39 +01:00
if ($profileName -eq $currentProfile) {
2024-12-13 20:06:30 +01:00
# Update the profile name
Set-ItemProperty -Path $profilePath -Name "ProfileName" -Value "WinApps"
Write-Host "Renamed profile to: WinApps"
}
}