The following script works exactly as it should on Windows 11 but fails on Windows 10…
- User
The following script works exactly as it should on Windows 11 but fails on Windows 10 "Pattern matching only works with the PRINT command" it says, can you fix it? @echo off REM ------------------------------------------------- REM Batch script to add two static routes via VPN REM -------------------------------------------------
REM Ensure the script is running as Administrator openfiles >nul 2>&1 if %errorlevel% NEQ 0 ( echo This script requires administrative privileges. echo Please run as Administrator. pause exit /b )
REM ------------------------------------------------- REM Define Variables REM ------------------------------------------------- set "VPN_ALIAS=GrecoTormenta"
REM Define server IPs set "SERVER_IP1=10.207.10.114" set "SERVER_IP2=10.24.10.49"
set "SUBNET_MASK=255.255.255.255"
REM ------------------------------------------------- REM Retrieve Interface Index using Get-NetIPConfiguration REM ------------------------------------------------- for /f "usebackq tokens=* delims=" %%j in (
powershell -NoProfile -Command ^ "Get-NetIPConfiguration -InterfaceAlias '%VPN_ALIAS%' | Select-Object -ExpandProperty InterfaceIndex") do set "IFINDEX=%%j"REM Check if Interface Index was found if "%IFINDEX%"=="" ( echo Error: Interface Index for VPN connection "%VPN_ALIAS%" not found. pause exit /b )
REM ------------------------------------------------- REM Retrieve VPN IPv4 Address using Get-NetIPAddress REM ------------------------------------------------- for /f "usebackq tokens=* delims=" %%g in (
powershell -NoProfile -Command ^ "Get-NetIPAddress -InterfaceAlias '%VPN_ALIAS%' -AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress") do set "GATEWAY=%%g"REM Check if IPv4 Address was found if "%GATEWAY%"=="" ( echo Error: IPv4 Address for VPN connection "%VPN_ALIAS%" not found. pause exit /b )
REM ------------------------------------------------- REM Add Route for SERVER_IP1 REM ------------------------------------------------- echo Adding route to %SERVER_IP1% via gateway %GATEWAY% on interface %IFINDEX%... route add %SERVER_IP1% mask %SUBNET_MASK% %GATEWAY% IF %IFINDEX% if %errorlevel% EQU 0 ( echo Route to %SERVER_IP1% successfully added. ) else ( echo Failed to add route to %SERVER_IP1%. Please check the details and try again. pause exit /b )
REM Make the route persistent echo Making the route to %SERVER_IP1% persistent... route -p add %SERVER_IP1% mask %SUBNET_MASK% %GATEWAY% IF %IFINDEX% if %errorlevel% EQU 0 ( echo Persistent route to %SERVER_IP1% successfully added. ) else ( echo Failed to add persistent route to %SERVER_IP1%. pause exit /b )
REM ------------------------------------------------- REM Add Route for SERVER_IP2 REM ------------------------------------------------- echo Adding route to %SERVER_IP2% via gateway %GATEWAY% on interface %IFINDEX%... route add %SERVER_IP2% mask %SUBNET_MASK% %GATEWAY% IF %IFINDEX% if %errorlevel% EQU 0 ( echo Route to %SERVER_IP2% successfully added. ) else ( echo Failed to add route to %SERVER_IP2%. Please check the details and try again. pause exit /b )
- Assistant