Created
October 2, 2021 14:12
-
-
Save myfingerhurt/098b767a9f882b14b7b10450f7844892 to your computer and use it in GitHub Desktop.
Remove any that begin with Network 1 2 3 4 5 6 7 8 9 for ZeroTie with self-elevating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
# PowerShell script that goes through all the network profiles in the registry and attempts to remove any that begin with "Network ". | |
# Must be run as admin. You need to remove the "-Whatif" parameter for the cmndlet to actually make changes. | |
#> | |
# Self-elevate the script if required | |
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { | |
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { | |
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments | |
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine | |
Exit | |
Read-Host -Prompt "Press Enter to exit" | |
} | |
} | |
Get-ChildItem 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\' | | |
ForEach-Object{ | |
$profilename = $_.GetValue('ProfileName') | |
if($profilename.StartsWith("Network ")){ | |
Write-Host "Removing item: $profilename" -ForegroundColor green | |
Remove-Item $_.PSPath -Whatif | |
}else{ | |
Write-Host "Skipping item:$profilename" -Fore blue -Back white | |
} | |
} | |
Read-Host -Prompt "Press Enter to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment