信じられないことです。test.ps1
これは、ファイル内のPowerShellコードスニペットです。
Set-StrictMode -Version 2
mkdir c:\tmp\1 # same with 'md c:\tmp\1'
開始し、スクリプトcmd.exe
を含むフォルダーに移動して実行します。test.ps1
c:\tmp>powershell ".\test.ps1"
これにより、次のエラーが発生します。
The variable '$_' cannot be retrieved because it has not been set.
At line:50 char:38
+ $steppablePipeline.Process($_ <<<< )
+ CategoryInfo : InvalidOperation: (_:Token) [], ParentContainsEr
rorRecordException
+ FullyQualifiedErrorId : VariableIsUndefined
なんで?
PowerShellコンソールから起動した場合は機能しますが、cmd.exeでは機能しません。私はこのバグをはるかに大きなスクリプトで発見しました。それはWTFの瞬間でした。
この単純なスクリプトの何が問題になっていますか?