diff --git a/remove-aovpn.ps1 b/remove-aovpn.ps1 new file mode 100644 index 0000000..edc0e1a --- /dev/null +++ b/remove-aovpn.ps1 @@ -0,0 +1,80 @@ +# Stop the RasMan service +Stop-Service -Name RasMan -Force + +# Short pause to ensure the service has completely stopped +Start-Sleep -Seconds 5 + +# Start the RasMan service +Start-Service -Name RasMan + +# Short pause to ensure the service has completely started +Start-Sleep -Seconds 5 + +# Try to remove the VPN connection +try { + Remove-VpnConnection -AllUserConnection -Name "Staedion AoVPN-D" -Force -ErrorAction Stop + Remove-VpnConnection -Name "Staedion AoVPN-U" -Force -ErrorAction Stop + Write-Output "VPN connection successfully removed." +} +catch { + Write-Error "Error removing the VPN connection: $_" +} + +# Path for DeviceTunnel +$regPathDeviceTunnel = "HKLM:\SYSTEM\CurrentControlSet\Services\RasMan\DeviceTunnel" + +# Check if the path for DeviceTunnel exists +if (Test-Path $regPathDeviceTunnel) { + # Retrieve and delete all subkeys + Get-ChildItem -Path $regPathDeviceTunnel | ForEach-Object { + Remove-Item -Path $_.PSPath -Recurse -Force + } + + # Retrieve and delete all values in the key + Get-Item -Path $regPathDeviceTunnel | ForEach-Object { + $_.GetValueNames() | ForEach-Object { + Remove-ItemProperty -Path $regPathDeviceTunnel -Name $_ + } + } + + Write-Output "All subkeys and values under $regPathDeviceTunnel have been deleted." +} +else { + Write-Output "The path $regPathDeviceTunnel was not found." +} + +# Path for ConfigJon +$regPathConfigJon = "HKLM:\SOFTWARE\ConfigJon" + +# Check if the path for ConfigJon exists +if (Test-Path $regPathConfigJon) { + # Delete the entire ConfigJon folder and its content + Remove-Item -Path $regPathConfigJon -Recurse -Force + Write-Output "The folder $regPathConfigJon and all its content have been deleted." +} +else { + Write-Output "The path $regPathConfigJon was not found." +} + +# Path for Tracked +$regPathTracked = "HKLM:\SOFTWARE\Microsoft\EnterpriseResourceManager\Tracked" + +# Check if the path for Tracked exists +if (Test-Path $regPathTracked) { + # Retrieve and delete all subkeys + Get-ChildItem -Path $regPathTracked | ForEach-Object { + Remove-Item -Path $_.PSPath -Recurse -Force + } + + # Retrieve and delete all values in the key + Get-Item -Path $regPathTracked | ForEach-Object { + $_.GetValueNames() | ForEach-Object { + Remove-ItemProperty -Path $regPathTracked -Name $_ + } + } + + Write-Output "All subkeys and values under $regPathTracked have been deleted." +} +else { + Write-Output "The path $regPathTracked was not found." +} \ No newline at end of file