Reputation: 679
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?
Upvotes: 1
Views: 6312
Reputation: 679
@Theo: Thanks for pointing me to the type casting. It has solved my issue!
[CmdletBinding()]
param (
[parameter(Mandatory = $true)][String]$Message,
[parameter(Mandatory = $true)][String[]]$Reciepient
)
Upvotes: 2