PowerShell 5.1 起動テンプレート(BAT:Shift_JIS / PS1:UTF-8 BOM)

1. 前提条件

2. 起動 BAT テンプレート(4 パターン)

2.1 引数なし × 非表示(Hidden)

@echo off
set SCRIPTNAME="sample.ps1"
start /b conhost.exe powershell -ExecutionPolicy Bypass -NoProfile -WindowStyle Hidden -File "%~dp0%SCRIPTNAME%"

2.2 引数なし × 表示(Normal)

@echo off
set SCRIPTNAME="sample.ps1"
start conhost.exe powershell -ExecutionPolicy Bypass -NoProfile -WindowStyle Normal -File "%~dp0%SCRIPTNAME%"

2.3 引数あり × 非表示(Hidden)

@echo off
set SCRIPTNAME="sample.ps1"
set ARG1=%1
set ARG2=%2
start /b conhost.exe powershell -ExecutionPolicy Bypass -NoProfile -WindowStyle Hidden -File "%~dp0%SCRIPTNAME%" -Arg1 "%ARG1%" -Arg2 "%ARG2%"

2.4 引数あり × 表示(Normal)

@echo off
set SCRIPTNAME="sample.ps1"
set ARG1=%1
set ARG2=%2
start conhost.exe powershell -ExecutionPolicy Bypass -NoProfile -WindowStyle Normal -File "%~dp0%SCRIPTNAME%" -Arg1 "%ARG1%" -Arg2 "%ARG2%"

3. PowerShell 側(UTF-8 BOM)の受け取り例

param(
    [string]$Arg1,
    [string]$Arg2
)

4. PowerShell 起動パラメータの説明