小编Tob*_*KKS的帖子

无法将参数绑定到参数,因为它是一个空字符串

从我创建并导入到主脚本中的模块调用函数时出现此错误:

 Run-RemoteScript : Cannot bind argument to parameter 'Targets' because it 
is an empty string.
At C:\Scripts\Script.ps1:114 char:39
+             Run-RemoteScript -Targets $targets -RunMethod $runMethod  ...
+                                       ~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Run-RemoteScript], 
ParameterBindingValidationException
+ FullyQualifiedErrorId : 
ParameterArgumentValidationErrorEmptyStringNotAllowed,Run-RemoteScript`
Run Code Online (Sandbox Code Playgroud)

在我的模块中,-Target被定义为这样的参数:

[Parameter(Mandatory, Position = 0)][String[]]$Targets,
Run Code Online (Sandbox Code Playgroud)

在我的主脚本(导入我的模块)中,$targets定义如下:

$Targets = Set-TargetList
Run Code Online (Sandbox Code Playgroud)

我曾尝试使用global脚本范围,但这不起作用。

powershell powershell-module

4
推荐指数
1
解决办法
6569
查看次数

标签 统计

powershell ×1

powershell-module ×1