@echo off REM ============================================================================ REM Fix-FirewallSubnet.bat REM Fixes WinRM HTTPS firewall rule to allow specific subnet(s) REM ============================================================================ REM Setup logging set "LOG_DIR=S:\DT\ADATA\SCRIPT\DEPLOY\LOGS" set "HOSTNAME=%COMPUTERNAME%" set "TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%" set "TIMESTAMP=%TIMESTAMP: =0%" set "LOG_FILE=%LOG_DIR%\%HOSTNAME%-%TIMESTAMP%-FIREWALL-FIX.txt" REM Create log directory if it doesn't exist if not exist "%LOG_DIR%" ( mkdir "%LOG_DIR%" 2>nul ) echo. echo ======================================== echo Fix WinRM Firewall Subnet echo ======================================== echo. echo Hostname: %COMPUTERNAME% echo Log File: %LOG_FILE% echo. REM Check for administrator privileges net session >nul 2>&1 if %errorLevel% neq 0 ( echo [ERROR] This script requires Administrator privileges. echo Please right-click and select "Run as Administrator" echo. pause exit /b 1 ) echo [OK] Running with Administrator privileges echo. REM Get the directory where this batch file is located set "SCRIPT_DIR=%~dp0" echo Script directory: %SCRIPT_DIR% echo. REM Check if PowerShell script exists if not exist "%SCRIPT_DIR%Fix-FirewallSubnet.ps1" ( echo [ERROR] Fix-FirewallSubnet.ps1 not found in script directory echo Please ensure all files are in the same directory echo. pause exit /b 1 ) echo [OK] Required files found echo. REM Execute PowerShell script with default subnets (management + shopfloor) echo Fixing firewall rule to allow subnets: echo - Management: 10.48.130.0/23 echo - Shopfloor: 10.134.48.0/24 echo. PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command ^ "& '%SCRIPT_DIR%Fix-FirewallSubnet.ps1' -AllowedSubnets '10.48.130.0/23,10.134.48.0/24'" > "%LOG_FILE%" 2>&1 if %errorLevel% neq 0 ( echo. echo [ERROR] Fix failed with error code: %errorLevel% echo. echo Log saved to: %LOG_FILE% pause exit /b %errorLevel% ) echo. echo ======================================== echo [SUCCESS] Firewall Fix Complete echo ======================================== echo Log saved to: %LOG_FILE% echo. pause