I have an array of Reciepients:
$reciepientList = @(
"foo"
"bar"
#...
)
I want to send a Message to all of them with a function using REST:
function Send-Message{
[CmdletBinding()]
param (
[parameter(Mandatory=$true)][String]$Message,
[parameter(Mandatory=$true)][String]$Reciepient
)
# My RESTful stuff goes here ...
Invoke-RestMethod ...
}
Sending my message fails:
Send-Message -Reciepient $reciepientList -Message "My message"
Output:
Send-Message: Cannot process argument transformation on parameter 'Reciepient'.
Cannot convert value to type System.String.
Any idea, how to tell Powershell to convert my Array to a String?
$reciepientListis not a Hash, but a string array. Change the parameter type casting from[string]to[string[]]. ([parameter(Mandatory=$true)][String[]]$Reciepient), or join the email addresses with a semi-colon (;), depending if your Send-Message function needs a combined string or an array of recipients.$reciepientList | % { Send-Message -Reciepient $_ -Message "Your message" }