@echo off

rem バッチファイルのフルパスを取得
rem set "fullpath=%~dp0%~nx0"
set "fullpath=%1"
shift

rem シフト後の引数を再構築
setlocal enabledelayedexpansion
:loop
if "%1"=="" goto end_loop
set "args="

:reconstruct
if "%1"=="" goto end_loop
set "args=!args! %1"
shift
goto reconstruct

:end_loop
:echo [!args!]


rem 変数 fullpath の前後の二重引用符を削除
set "fullpath=%fullpath:"=%"

for %%I in ("%fullpath%") do set "dirpath=%%~dpI"
for %%I in ("%fullpath%") do set "filename=%%~nxI"
for %%I in ("%fullpath%") do set "filebody=%%~nI"

:echo fullpath=%fullpath%
:echo dirpath=%dirpath%
:echo filename=%filename%
:echo filebody=%filebody%

echo run_powershell_script.bat: Run [powershell -NoProfile -ExecutionPolicy Bypass -File "%dirpath%%filebody%.ps1" %*]
powershell -NoProfile -ExecutionPolicy Bypass -File "%dirpath%%filebody%.ps1" !args!

endlocal
