I am getting this error when calling a function from a module that I have created and imported into my main script:
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`
In my module, -Target is defined as a parameter like this:
[Parameter(Mandatory, Position = 0)][String[]]$Targets,
In my main script (which imports my module), $targets is defined like this:
$Targets = Set-TargetList
I have tried using a global script scope, but this did not work.


Set-TargetListreturn. Is that a[string[]]array?Set-TargetListreturns a[string[]]array.$Targetsin your script? You can use$Targets.GetType(). The error says that$targetsis an empty string, not a string array. Thx$Targets.GetType()whereever$Targetsis referenced, and they all returnedString[]andSystem.Array[string]can be$null. You need to validate each entry in your array before using it:if ($null -ne $item) { ... }