Skip to content

Instantly share code, notes, and snippets.

@myfingerhurt
Created October 2, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myfingerhurt/098b767a9f882b14b7b10450f7844892 to your computer and use it in GitHub Desktop.
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
<#
# 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