Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot bind argument to parameter because it is an empty string

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.

like image 399
Tobias KKS Avatar asked Nov 01 '18 10:11

Tobias KKS


People also ask

Why cannot bind argument to parameter XXXXX'?

Cannot bind argument to parameter xxxxx' because it is an empty string. I try to script for office 365 adding distribution groups and then add users later. But my code does not work until the end .. (I learn the powershell ...) Thnaks you. $Users is empty bcoz of this line.

Why Runrun-remotescript can't bind argument to parameter'targets'?

Run-RemoteScript : Cannot bind argument to parameter 'Targets' because it is an empty string.

Why convert-repositoryuri cannot bind argument to parameter 'Uri'?

[Bug] Convert-RepositoryUri : Cannot bind argument to parameter 'Uri' because it is an empty string. · Issue #4917 · ScoopInstaller/Scoop · GitHub tinygo-org/tinygo#2821 build: install scoop without update to avoid bug in ScoopInstaller tinygo-org/tinygo#2853 Resolve running installer as admin (#5) MinoruSekine/setup-scoop#6

Why is it being rejected when I pass a string parameter?

It was rejected when at least one of the member strings was empty or null. Either set AllowEmptyString as an attribute in the parameter you're calling, or check whether the members are not empty strings before passing them. Show activity on this post.


1 Answers

Probably a late answer, but in case others have a similar issue.

In my case, it was an array of strings. It was rejected when at least one of the member strings was empty or null.

Either set AllowEmptyString as an attribute in the parameter you're calling, or check whether the members are not empty strings before passing them.

like image 74
Vadim Berman Avatar answered Oct 22 '22 10:10

Vadim Berman