Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Passing string array to function creates error

$
0
0

I am trying to call a function with the following parameter signature:

      Param (
        [Parameter(Mandatory=$true)][string]$Subject,
        [Parameter(Mandatory=$true)][string]$JobResult,
        [Parameter(Mandatory=$true)]$Body,
        [Parameter(Mandatory=$true)][System.String[]] $Recipients
      )


I invoke it with:

[string[]] $ToAddresses = @("abc@xyz.com", "sa@xyz.com")
Send-HtmlEmail -Subject "Save to Server" -JobResult "Results" -Body "New Body", -Recipients  $ToAddresses

which returns the error

 A positional parameter cannot be found that accepts argument 'System.String[]'.

If I change the Recipient argument to

Send-HtmlEmail -Subject "Save Outlook to Server" -JobResult "Results" -Body "New Body", -Recipients  (,$ToAddresses)

the error is 

A positional parameter cannot be found that accepts argument 'System.Object[]'
How can I do this correctly? 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>