Skip to content

Instantly share code, notes, and snippets.

@LivingGhost
Created July 14, 2020 02:40
Show Gist options
  • Save LivingGhost/4b5db5726a596a846d774876bb8c070b to your computer and use it in GitHub Desktop.
Save LivingGhost/4b5db5726a596a846d774876bb8c070b to your computer and use it in GitHub Desktop.
batファイル内で直接PowerShellのコードを実行する (さらに自身のウィンドウを非表示にする)
@(echo '> NUL
echo off)
setlocal enableextensions
echo %~n0%~x0
if "%~1" neq "RESTARTED" ( goto RESTART )
set "THIS_PATH=%~f0"
set "PARAM_1=%~2"
PowerShell.exe -Command "iex -Command ((gc \"%THIS_PATH:`=``%\") -join \"`n\")"
exit /b %errorlevel%
:RESTART
powershell -NoProfile -ExecutionPolicy unrestricted -Command "Start-Process \"%~f0\" -ArgumentList \"RESTARTED %~1\" -WindowStyle Hidden -Verb runas"
exit
') | sv -Name TempVar
# 以降にPowershellコマンドを記載していく
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment