Windows 10 Pro 21H2 (OS Build 19044.1566)
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.1320
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1320
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\> Write-Host ( ".NET Framework: {0}" -f (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Version )
.NET Framework: 4.8.04084
下記2ファイルを同一フォルダ階層に配置し、ps_exit_test.bat
を実行
-
ps_exit_test.bat
@echo off PowerShell.exe -NoProfile -ExecutionPolicy RemoteSigned -File %~dpn0.ps1 %* echo ERRORLEVEL=%ERRORLEVEL% pause
-
ps_exit_test.ps1
# ここをいろいろ変えてみる
ERRORLEVEL=0
ERRORLEVEL=0
ERRORLEVEL=1
ERRORLEVEL=65535
最大値は 2^32 - 1
らしい
ERRORLEVEL=2147483647
超えると 0
になる
ERRORLEVEL=0
それ以上大きくしても 0
にしかならない
ERRORLEVEL=0
最小値は -(2^32)
らしい。取りうる値は Int32 ?
ERRORLEVEL=-2147483648
ERRORLEVEL=0
ERRORLEVEL=0
ERRORLEVEL=1
Cannot convert argument "exitCode", with value: "-2147483649", for "Exit" to type "System.Int32": "Cannot convert
value "-2147483649" to type "System.Int32". Error: "Value was either too large or too small for an Int32.""
…
ERRORLEVEL=0
Cannot convert argument "exitCode", with value: "2147483648", for "Exit" to type "System.Int32": "Cannot convert value
"2147483648" to type "System.Int32". Error: "Value was either too large or too small for an Int32.""
…
ERRORLEVEL=0
exitCode
は Int32 の範囲で指定する
「.NET Framework のバージョン教えてください」と聞く代わりに実行してもらっているやつ