🙆♀️
PowerShellを検出する (バッチファイル)
PowerShellを検出するバッチファイルです。
rem Detect PowerShell
set POWERSHELL=
where.exe /r "%SystemRoot%\system32" "powershell.exe" > "%WORKING_DIR%\PowerShell-FilePath.txt" 2>nul
if %ERRORLEVEL% equ 0 (
rem set POWERSHELL=powershell.exe
for /f "usebackq delims=" %%a in ("%WORKING_DIR%\PowerShell-FilePath.txt") do (
set POWERSHELL=%%a
)
)
del "%WORKING_DIR%\PowerShell-FilePath.txt"
where.exe /r "%PROGRAMFILES%" "pwsh.exe" > "%WORKING_DIR%\Pwsh-FilePath.txt" 2>nul
if %ERRORLEVEL% equ 0 (
rem set POWERSHELL=pwsh.exe
for /f "usebackq delims=" %%a in ("%WORKING_DIR%\Pwsh-FilePath.txt") do (
set POWERSHELL=%%a
)
)
del "%WORKING_DIR%\Pwsh-FilePath.txt"
if not defined POWERSHELL (
echo PowerShell is not installed.
exit /b 1
)
echo PowerShell: %POWERSHELL%
Discussion