2
私は単純なスクリプトSet-StrictModeはパラメータブロックと互換性がありませんか?
Param([string] $myStringValue)
echo $myStringValue
を持っていると私は./test.ps1 -myStringValue steve
とそれを呼び出すときに、それだけで正常に動作します。
しかし、私が最初に設定-StrictModeを追加した場合:
Set-StrictMode -Version Latest
Param([string] $myStringValue)
echo $myStringValue
私は次のエラーを取得:
> ./test.ps1 -myStringValue steve
The variable '$myStringValue' cannot be retrieved because it has not been set.
At D:\code\cadgraphics\test.ps1:2 char:20
+ Param([string] $myStringValue)
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (myStringValue:String) [], RuntimeException
+ FullyQualifiedErrorId : VariableIsUndefined
The variable '$myStringValue' cannot be retrieved because it has not been set.
At D:\code\cadgraphics\test.ps1:3 char:10
+ echo $myStringValue
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (myStringValue:String) [], RuntimeException
+ FullyQualifiedErrorId : VariableIsUndefined
私はちょうど$myStringValue
$myStringValue = ''
Set-StrictMode -Version Latest
Param([string] $myStringValue)
echo $myStringValue
それを設定しようとしましたParamブロックでチョークしました:
Param : The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At D:\code\cadgraphics\test.ps1:3 char:5
+ Param([string] $myStringValue)
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (Param:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
私は間違っていますか?
おそらく、パラメータを必須としてマークするか、何かに初期化することができます。 –