Ich habe ein einfaches SkriptIst Set-StrictMode mit Parameterblöcken nicht kompatibel?
Param([string] $myStringValue)
echo $myStringValue
bekam Und wenn ich es mit ./test.ps1 -myStringValue steve
nennen, es funktioniert ganz gut.
Aber wenn ich hinzufügen Set-StrictMode zum Anfang:
Set-StrictMode -Version Latest
Param([string] $myStringValue)
echo $myStringValue
ich folgende Fehlermeldungen erhalten:
> ./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
Ich versuchte $myStringValue
vorher
$myStringValue = ''
Set-StrictMode -Version Latest
Param([string] $myStringValue)
echo $myStringValue
aber diese Einstellung nur ließ es auf dem Param Block ersticken:
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
Was mache ich falsch?
Vielleicht können Sie den Parameter als obligatorisch markieren oder initialisieren. –