I'm trying to create a cmdlet function in powershell with 2 arguments. I want one of those 2 arguments to be a ConsoleColor but ISE complains and says there is a Missing ')' in function parameter list. But I can't find this missing ).
Here is my function:
function Log {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true, ValueFromRemainingArguments=$true)]
[AllowNull()]
[AllowEmptyString()]
[AllowEmptyCollection()]
[string[]]$messages,
# If I remove the following parameter, everything works fine
[System.ConsoleColor]$color = Default # ISE Complains here before `=`
)
if (($messages -eq $null) -or ($messages.Length -eq 0)) {
$messages = @("")
}
foreach ($msg in $messages) {
Write-Host $msg -ForegroundColor $color
$msg | Out-File $logFile -Append
}
}
I'm not very good in powershell so it might be something stupid that I just don't know yet.