Newbie to Batch scripting here. I'm trying to capture the output of a Batch 'function' (not exactly since Batch lacks built-in support for functions) to a variable. Here is my code:
@echo off
setlocal enabledelayedexpansion
goto main
:: Functions
:runps
powershell -NoProfile -ExecutionPolicy Bypass -Command "%1"
goto :eof
:appendToPath
set OLDPATHPS="[Environment]::GetEnvironmentVariable('PATH', 'User')"
for /f %%i in ('call :runps %OLDPATHPS%') do ^
set OLDPATH=%%i
:: ...
goto :eof
:main
call :appendToPath
When I run this I get the following output from the console:
Invalid attempt to call batch label outside of batch script.
Why does this happen and what can I do to fix it?